- Joined
- Jul 6, 2006
- Messages
- 7
- Reaction score
- 0
I am new to VB and trying to write a VB code that will select variable ranges but cant figure it out.
Basically I have 1000+ rows of data and is separated by just "====" and I would like to sort each set of data that ranges from 1 "====" to another. Because the data is updated weekly the rows which originally had "====" might not be the same another which prevents me from using constant.
I originally tried searching for all the row indexes with "====" and storing them in an array. After I would just sort each set of data ranging from 1 array index to the next. But which ever way I tried, in my code such as...
Range ("index1" , "index2").select
where index1 and index2 is a string for the cell numbers being used, I get the error "method 'Range' of object '_Global' failed"
Is it possible to input the parameters for Range as variables instead of constants or any other functions I may use?
Also the 2nd part of the code that sorts the data...
Selection.Sort Key1:=Range("E2"), Order1:=xlAscending, Key2:=Range("D2") _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2 _
:=xlSortNormal
instead of having key1:=Range("E2") and Key2:=("D2") is there a way to make the Keys dynamic such that it would by like "Ei" and "Di" where i is the row number for where a new set of data begins.
Any help would be appreciated thanks,
Basically I have 1000+ rows of data and is separated by just "====" and I would like to sort each set of data that ranges from 1 "====" to another. Because the data is updated weekly the rows which originally had "====" might not be the same another which prevents me from using constant.
I originally tried searching for all the row indexes with "====" and storing them in an array. After I would just sort each set of data ranging from 1 array index to the next. But which ever way I tried, in my code such as...
Range ("index1" , "index2").select
where index1 and index2 is a string for the cell numbers being used, I get the error "method 'Range' of object '_Global' failed"
Is it possible to input the parameters for Range as variables instead of constants or any other functions I may use?
Also the 2nd part of the code that sorts the data...
Selection.Sort Key1:=Range("E2"), Order1:=xlAscending, Key2:=Range("D2") _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2 _
:=xlSortNormal
instead of having key1:=Range("E2") and Key2:=("D2") is there a way to make the Keys dynamic such that it would by like "Ei" and "Di" where i is the row number for where a new set of data begins.
Any help would be appreciated thanks,