Forum Discussion
replacing as variables in sort,subtotal macros
- Jul 06, 2018I see it's in the previous routine, you therefore need to pass it along with the other variables to the SortSubtotal routine
Hi Lorenzo
I'd recommend defining a range name for the first cell you want to sort and resizing the range based on the Integer Last Cell
e.g I named cell C2 "SortRef"
Avoiding hard-coding cell references and sheet names in your code is the key to preventing it from breaking easily as people insert/delete rows and columns or sheets are renamed.
Sub Sort()
Dim LastRow As Integer
Dim rngSort As Range
LastRow = 20
Set rngSort = Range("SortRef").Resize(LastRow, 1)
rngSort.Sort rngSort
Set rngSort = Nothing
End Sub
You should avoid referencing sheet names in your code. e.g. "client"
Best to refer to range names or sheet numbers e.g. Sheet1.Activate
The 3, could be set as an Integer which is any number ā32,768 to 32,767
BTW
how do you put the codes inside a 'box' like the one you did for Sub Sort()
thanks
- Wyn HopkinsJul 06, 2018MVP
Did you change mrng to a string?
to enter code, click in the reply button and then there is a </> icon
- Lorenzo KimJul 06, 2018Bronze Contributor
Mr. Hopkins
pardon me, I do not see in this Message box the </> icon ..
where could it be? sorry for being so noob...
you mean I have to click this icon then type the codes for it to be inside a box?
man thanks
- Wyn HopkinsJul 06, 2018MVP
Hi
Click Reply
Then
</> and paste your code
- Lorenzo KimJul 06, 2018Bronze Contributor
Mr. Hopkins
I changed the mrng to string and still error, below is the image for the error..
I'm sure msheet as variant is correct as I had used it in ClearSheets() ..
I think the culprit is mcol, I've tried integer, long but it isn't working- maybe the way it should be written beside GroupBy:=mcol??. or maybe mrng?
many thanks
- Wyn HopkinsJul 06, 2018MVPTry preceding SortSubtotal with Call Module1.SortSubtotal( etc...)