Set Last Row Error as Object Required

JohnA7

New Member
Joined
Apr 7, 2016
Messages
7
Set Last Row Error as Object Required


Hi all. I have this down at work and now I'm on my home laptop and it's not working.

Laptop is using Excel 2016. I'm trying to set the last row starting from A7 (there's random stuff that changes between A1-A6, but code starts at A7), worksheet name is "State Info".

I'm getting Compile Error: Object Required on "LRowStateInfo = StateInfo.Range(StateInfo.Rows.Count,"A").End(xlUp).Row"

There also has to be an easier way to do the piece inside the With no? Maybe a for each or do loop?
For color, "Data Table" is going to be a large table, where states can be added as rows, and information can be added as columns. "State Info" is a page where you type in the state and get all the information in the data table.

I'm really sorry if this has been addressed or answered before. I've searched for 2 hours now and have tried a bunch of different fixes, but no luck. I wouldn't open a new thread if I wasn't completely stumped. I'm probably missing something stupid. I have something exactly like this on my work computer (Excel 2010) and it works just fine.

Code:
Sub KUDT_StateInfo()


Dim Wkbk As Workbook
Dim DataTable As Worksheet
Dim StateInfo As Worksheet
Dim FinalPayRules As Worksheet
Dim LRowStateInfo As Long
Dim LColStateInfo As Long
Dim LRowDataTable As Long
Dim LColDataTable As Long
Dim LRowFinalPay As Long
Dim LColFinalPay As Long




Set Wkbk = ActiveWorkbook
Set DataTable = Wkbk.Sheets("Data Table")
Set StateInfo = Wkbk.Sheets("State Info")
Set FinalPayRules = Wkbk.Sheets("Final Pay Rules")
Set LRowStateInfo = StateInfo.Range(StateInfo.Rows.Count, "A").End(xlUp).Row




With StateInfo
'Fills Row Labels
    Range("A7").Value = "Topic"
    Range("A8").Value = DataTable.Range("B1")
    Range("A9").Value = DataTable.Range("C1")
    Range("A10").Value = DataTable.Range("D1")
    Range("A11").Value = DataTable.Range("E1")
    Range("A12").Value = DataTable.Range("F1")
    Range("A13").Value = DataTable.Range("G1")
    Range("A14").Value = DataTable.Range("H1")
    Range("A15").Value = DataTable.Range("I1")
    Range("A16").Value = DataTable.Range("J1")
    Range("A17").Value = DataTable.Range("K1")
    Range("A18").Value = DataTable.Range("L1")
    Range("A19").Value = DataTable.Range("M1")
    Range("A20").Value = DataTable.Range("N1")
    Range("A21").Value = DataTable.Range("O1")
    Range("A22").Value = DataTable.Range("P1")
    
'Lookup Result based on State
    Range("B8").Formula = "=VLOOKUP(B3,'Data Table'!A:Z,2,0)"
    Range("B9").Formula = "=VLOOKUP(B3,'Data Table'!A:Z,3,0)"
    Range("b10").Formula = "=VLOOKUP(B3,'Data Table'!A:Z,4,0)"
    Range("b11").Formula = "=VLOOKUP(B3,'Data Table'!A:Z,5,0)"
    Range("b12").Formula = "=VLOOKUP(B3,'Data Table'!A:Z,6,0)"
    Range("b13").Formula = "=VLOOKUP(B3,'Data Table'!A:Z,7,0)"
    Range("b14").Formula = "=VLOOKUP(B3,'Data Table'!A:Z,8,0)"
    Range("b15").Formula = "=VLOOKUP(B3,'Data Table'!A:Z,9,0)"
    Range("b16").Formula = "=VLOOKUP(B3,'Data Table'!A:Z,10,0)"
    Range("b17").Formula = "=VLOOKUP(B3,'Data Table'!A:Z,11,0)"
    Range("b18").Formula = "=VLOOKUP(B3,'Data Table'!A:Z,12,0)"
    Range("b19").Formula = "=VLOOKUP(B3,'Data Table'!A:Z,13,0)"
    Range("b20").Formula = "=VLOOKUP(B3,'Data Table'!A:Z,14,0)"
    Range("b21").Formula = "=VLOOKUP(B3,'Data Table'!A:Z,15,0)"
    Range("b22").Formula = "=VLOOKUP(B3,'Data Table'!A:Z,16,0)"
    
    Range("A7:A" & LRowStateInfo).ColumnWidth.AutoFit
    
End With
End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
LRowStateInfo is data type Long. Its not an object, so the Set keyword should not be used. Change the line to
Code:
LRowStateInfo = StateInfo.Range(StateInfo.Rows.Count, "A").End(xlUp).Row
 
Upvote 0
Thank you. Tried that but then it draws error down to when I try to autofit columns.

Now I'm getting "Object Required" error here.. I thought my object was "With State Info". Maybe I don't understand this stuff as well as I thought.

removing the code in between:

Code:
Dim Wkbk As Workbook
Dim DataTable As Worksheet
Dim StateInfo As Worksheet
Dim FinalPayRules As Worksheet
Dim LRowStateInfo As Long\

Set Wkbk = ActiveWorkbook
Set DataTable = Wkbk.Sheets("Data Table")
Set StateInfo = Wkbk.Sheets("State Info")
Set FinalPayRules = Wkbk.Sheets("Final Pay Rules")
LRowStateInfo = StateInfo.Range(StateInfo.Rows.Count, "A").End(xlUp).Row


With StateInfo
 Range("A7:A" & LRowStateInfo).Columns.ColumnWidth.AutoFit

End With
End Sub
 
Upvote 0
Got it sorry, long day. Thank you!

Code:
Sub KUDT_StateInfo()


Dim Wkbk As Workbook
Dim DataTable As Worksheet
Dim StateInfo As Worksheet
Dim FinalPayRules As Worksheet
Dim LRowStateInfo As Long
Dim LColStateInfo As Long
Dim LRowDataTable As Long
Dim LColDataTable As Long
Dim LRowFinalPay As Long
Dim LColFinalPay As Long

Set Wkbk = ActiveWorkbook
Set DataTable = Wkbk.Sheets("Data Table")
Set StateInfo = Wkbk.Sheets("State Info")
Set FinalPayRules = Wkbk.Sheets("Final Pay Rules")
LRowStateInfo = StateInfo.Cells(Rows.Count, 1).End(xlUp).Row


With StateInfo
 Range("A7:A" & LRowStateInfo).Columns.AutoFit
End With

End Sub
 
Upvote 0

Forum statistics

Threads
1,221,418
Messages
6,159,791
Members
451,589
Latest member
Harold14

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