Const Original = "Hello"
Const Final = "No"
Sub TEST()
Dim LR_Original, LR_Final As Integer
LR_Original = Workbooks(Original).Worksheets("Hello1").Cells(Columns.Count, 1).End(xlToLeft).Column
End Sub
When I debug it, it seems to be unable to get a value of the last column.
I think I'm doing something wrong but not sure what...
First a peculiarity of Visual Basic: the declaration
Dim LR_Original, LR_Final As Integer
defines only LR_Final as an Integer; no data type is specified for LR_Original and hence it is defined as a Variant. If you want both to be Integers, you must use
is dangerous if Original is not the active workbook. Because you don't specify what Columns belongs to, it is assumed to be the Columns collection of the active worksheet in the active workbook. If for example the active workbook is an Excel 2007/2010 workbook and Original an Excel 97-2003 workbook, the number of columns will not be the same.
Moreover, it is incorrect: in Cells, you must first specify the row, then the column. So to get the column number of the last filled column in row 1, you should use