I am reworking the code in an older worksheet to update it and make it more efficient.
I have a subroutine that formats a data table but I am getting an error where I dont see why I am getting one. My VBA is a bit rusty but the following code should be working
Sub FormatPnLDataTable(tableRange As Range)
Dim tempRange As Range, ws As Worksheet
Dim lStartRow As Long, lEndRow As Long, lLastCol As Long
Set ws = Sheets("PandLDataTable")
Application.CutCopyMode = False
lStartRow = tableRange.Row
lEndRow = lStartRow + tableRange.Rows.Count
lLastCol = tableRange.Columns.Count
'format the whole table with border
With tableRange
'format borders
'code removed for brevity
End With
'set range for the top row of table
Set tempRange = ws.Range(Cells(lStartRow, 1), Cells(lStartRow, lLastCol))
The code is erring on this line
Set tempRange = ws.Range(Cells(lStartRow, 1), Cells(lStartRow, lLastCol))
but the worksheet (ws) is valid, and the variables all have their proper values for this particular instance, lStartRow is 1, lEndRow is 15 and lLastCol is 35