Selecting cell in VBA AND sorting
Hello all, I have 2 questions, which are both probably extremely easy for you experienced users. Any help would be much appreciated.
1. Why does something like
Code:
Worksheets("Sheet1").Range("B1").Select
not work? Is the only way to accomplish this to do
Code:
Worksheets("Sheet1").Select
Range("B1").Select
???
2. As far as sorting, starting in Excel 2007, you can sort with up to 255 sort fields, right? I noticed that selecting some range and doing .Sort and then typing in Key1:= and Key2:= and Key3:= works, but only up to 3 sort fields can be used in this way. Why is that? I have found an alternative (from recording a macro). Is this the only way? It would be doing something like
Code:
With ActiveWorkbook.Worksheets("sheet1").Sort
.SortFields.Clear
.SortFields.Add Key:=Range("B1")
and add more keys as you need, then later
.SetRange Range("A1:X30") ' or whatever
.Apply
End With
That is, using that method, you can add more than 3 keys and it works just fine.
Also, regarding this question, my number of rows might change from time to time and I don't want to have to redo the code each time. Can I use
.SetRange UsedRange
to get all my data in there?
Thanks!
Re: Selecting cell in VBA AND sorting
Quote:
.SetRange UsedRange
did you try it?
Re: Selecting cell in VBA AND sorting
Quote:
Originally Posted by
westconn1
did you try it?
No, I didn't. My code is all at work. I'll probably try it when I get there. But, there was nothing wrong with asking just in case. For example, if it doesn't work and you happen to know that, then you could tell me a way that would work, if you happen to know that.