[RESOLVED] VB6 - Excel.Selection.Sort
I made a program that takes in an excel file, then formats it the way it's supposed to look for my job, and saves it. It works great until a certain point. The first time you load a file into it and have it converted it works fine...after the conversion, though, when you load the next file and convert it I get an error on this line:
Code:
objExcel.Selection.Sort Key1:=Range("F2"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
The error I'm getting is:
"Method 'Range' of object '_Global' failed"
Does anyone know why this might be the case? I can't imagine what happens between the first conversion and the second conversion that causes that line not to work!
Thanks guys, appreciate it!
Re: VB6 - Excel.Selection.Sort
Never mind! haha
I changed
to
Code:
Key1:=objWorksheet.Range("F2")
Re: [RESOLVED] VB6 - Excel.Selection.Sort
The problem is that you have used Range("F2"), without specifying what it belongs to.
As there is no Range object/function in VB, it causes lots of confusion, and thus bugs.
You should be using a parent object, eg: objSheet.Range("F2")
edit: slightly too slow it seems!