ConnectionString
ConnectionString
' Open the workbook and set the reference to the opened workbook
Set strstrExcelFilePath = Workbooks.Open(strExcelFilePath)
Set strWorkSheet = strstrExcelFilePath.Sheets(strExcelSheetName) ' Set the
worksheet to the provided sheet name
' Find the last used column (using the first row to determine the last used
column)
lastCol = strWorkSheet.Cells(1,
strWorkSheet.Columns.Count).End(xlToLeft).Column
' Find the highest row with data across all columns (loop through each column)
highestRow = 1 ' Initialize highestRow to row 1
For j = 1 To lastCol
' Find the last row in each column
highestRow = WorksheetFunction.Max(highestRow,
strWorkSheet.Cells(strWorkSheet.Rows.Count, j).End(xlUp).Row)
Next j
' Check if there are values in the other columns (B to the last column)
hasValue = False
For j = 2 To lastCol
If strWorkSheet.Cells(i, j).Value <> "" Then
hasValue = True
Exit For
End If
Next j
' If there are values in other columns (and column A is empty), fill in the
file name in column A
If hasValue And strWorkSheet.Cells(i, 1).Value = "" Then
strWorkSheet.Cells(i, 1).Value = currentstrExcelFilePath
End If
Next i
' Clean up
Set strWorkSheet = Nothing
Set strstrExcelFilePath = Nothing
End Sub