Compile error end of statement to read to end of data set instead of a set number of rows

fvisions

Board Regular
Joined
Jul 29, 2008
Messages
191
Office Version
  1. 365
Platform
  1. Windows
Compile error: Expected: end of statement
I am changed my code to read column V to endo or the full worksheet, it was v2:v1000 but sometimes there are more than 1000 rows and I am receiving the compile error. I am not sure who to correct this.
Dim LastRow As Long
LastRow = Cells(Rows.Count, 2).End(xlUp).Row
VBA Code:
ActiveWorkbook.Worksheets("Installation wkg").Sort.SortFields.Add2 Key:=range _
        ("V2:V" & LastRow).SortOn:= xlSortOnValues, Order:=xlAscending, DataOption:= _
        xlSortNormal
 
It's to do with the version of Excel, not Windows.
 
Upvote 0

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
You need Add2 for the new SortFields like Geography and Stocks to work.
 
Upvote 0

Forum statistics

Threads
1,214,998
Messages
6,122,639
Members
449,093
Latest member
Ahmad123098

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top