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
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Do you realize that you are checking column B (and not column V) to locate the last row?
What is your value of "LastRow"?
You can get it like this:
VBA Code:
Dim LastRow As Long
LastRow = Cells(Rows.Count, 2).End(xlUp).Row
MsgBox LastRow
Also, are you on the "Installation wkg" sheet when this part of the code is running?
If not, you will need to change your code above to include the sheet reference.
 
Upvote 0
Do you realize that you are checking column B (and not column V) to locate the last row?
What is your value of "LastRow"?
You can get it like this:
VBA Code:
Dim LastRow As Long
LastRow = Cells(Rows.Count, 2).End(xlUp).Row
MsgBox LastRow
Also, are you on the "Installation wkg" sheet when this part of the code is running?
If not, you will need to change your code above to include the sheet reference.
Yes this is only part of the code. The other codes for looking at the last row is with column b for a vlookup of various other columns. This section of code is to sort the full spreadsheet columns A:AD by 3 criteria. the debug is highlighting on the colon/equals at the .sorton:= in the code does this help?
 
Upvote 0
Do you realize that you are checking column B (and not column V) to locate the last row?
What is your value of "LastRow"?
You can get it like this:
VBA Code:
Dim LastRow As Long
LastRow = Cells(Rows.Count, 2).End(xlUp).Row
MsgBox LastRow
Also, are you on the "Installation wkg" sheet when this part of the code is running?
If not, you will need to change your code above to include the sheet reference.
VBA Code:
 LastRow = Cells(Rows.Count, 2).End(xlUp).Row
 
Upvote 0
The word "range" in " "Key:=range _" should be capitalized.
The fact that it is not seems to imply that you may have a variable, procedure, or function named "range".
That is a big no-no. You should never use reserved words (names of existing functions, objects, or properties) as the names of your variables or procedures.
That can cause unpredictable behavior and errors.
 
Upvote 0
You have a full stop before SortOn it should be a comma.
 
Upvote 0
Ok updated the Cap and received a syntax error. Sorry I am not good at compile errors.
VBA Code:
  ActiveWorkbook.Worksheets("Installation wkg").Sort.SortFields.Add2 Key:=Range _
        ("v2:v" & LastRow).SortOn:= xlSortOnValues, Order:=xlAscending, DataOption:= _
        xlSortNormal
 
Upvote 0

Forum statistics

Threads
1,215,491
Messages
6,125,104
Members
449,205
Latest member
ralemanygarcia

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