Below is a copy of my data. I've been trying to find the last column 1 (so in this example, it should be 4, since last column is C and plus 1). The code I'm using is to determine last column is:
lastColumn = Cells(lastRow, Columns.Count).End(xlToLeft).Column
But I keep getting 2?
CodePudding user response:
lastColumn = Cells(5, Columns.Count).End(xlToLeft).Column
result will be 3 (last column on row 5)
lastColumn = Cells(lastRow, Columns.Count).End(xlToLeft).Column
result will be 2 (last column on row 10)
CodePudding user response:
lastColumn = Cells(**5**, Columns.Count).End(xlToLeft).Column
Was using lastrow and in that row, only two columns were filled. Used the header row instead.