fetch cell value to activecell
Posted: Wed Aug 02, 2023 11:50 am
Hi there
i have some codes to copy values from file in a folder of sharedrive .it is not working due to last row containing blank cells
thanks
i have some codes to copy values from file in a folder of sharedrive .it is not working due to last row containing blank cells
Code: Select all
Dim wb As Workbook
Dim ws As Worksheet
Dim cellValue As Variant
Dim strPath As String
Dim strWorkbookName As String
Dim strSheetName As String
Dim strCellAddress As String
strPath = "Z:\Finance-Dept\6. End of Month_EoM\2. End of Month_EoM for 2023\7. July 2023\"
strWorkbookName = "Fixed Assets Depreciation as of Jul 23.xlsx"
strSheetName = "FA List Update"
strCellAddress = "" ' Initialize the cell address
Set wb = Workbooks.Open(strPath & strWorkbookName)
Set ws = wb.Sheets(strSheetName)
Dim lastRow As Long
lastRow = ws.Cells(ws.Rows.Count, "D").End(xlUp).Row
Dim i As Long
For i = 4 To lastRow
If Right(ws.Cells(i, "D"), 5) = "Total" Then
strCellAddress = "L" & i
Exit For
End If
Next i
If strCellAddress <> "" Then
cellValue = ws.Range(strCellAddress).Value
ActiveCell.Value = cellValue
End If
wb.Close False
End Sub