I found that the following code doesn't return the last used row number in that particular column.
ThisWorkbook.Sheets(1).Cells(max_row, last_data_column + 1).End(xlUp).Row
What it returns is the last used row number in the Excel table.
I have an Excel table with the range A1:AB142. In the last row (142), only column B has data, the rest being empty. The above code returns 142, not 141, no matter what the last_data_column is (I tried 22, and 23).
Similarly,End(xlDown) doesn't work properly. Even though only W1 has data and the rest of the first row is blank,
ThisWorkbook.Sheets(1).Range("W1").End(xlDown).Row
gives 2, when W142 is blank and W1 to W141 are not blank.
How to find the last empty cell in a particular column in an Excel table?,