Hi. It looks like there is no knowledge at all in VBA, just copy - paste. Try the modified code:
Option Explicit
Sub SMBCFUNDS_by_MikeVol()
Dim wbPath As String: wbPath = "R:\Shipping Group\- SMBC INCOMING FUND REPORTS.xlsm"
Application.ScreenUpdating = False
With ActiveSheet
.AutoFilterMode = False
.Range(.Cells(4, 26), .Cells(4, 33)).AutoFilter
With .Range("$Z$4:$AG$" & .Cells(.Rows.Count, "Z").End(xlUp).Row)
.AutoFilter Field:=5, Criteria1:="="
.AutoFilter Field:=1, Criteria1:="SMBC"
End With
Dim visibleRows As Long: visibleRows = .Range("$Z$5:$Z$" & .Cells(.Rows.Count, "Z").End(xlUp).Row).SpecialCells(xlCellTypeVisible).Count
Dim lastRow As Long: lastRow = .Cells(.Rows.Count, "Z").End(xlUp).Row
If visibleRows <= 1 Then
.ShowAllData
MsgBox "No rows found matching the criteria. Process stopped."
Application.ScreenUpdating = True
Exit Sub
End If
If FileExists(wbPath) Then
Dim wbFile As Workbook: Set wbFile = Workbooks.Open(wbPath, ReadOnly:=True)
Dim ws As Worksheet: Set ws = wbFile.Worksheets("USD&JPY")
Dim wbName As String: wbName = wbFile.Name
With .Range("AD5:AE" & lastRow).SpecialCells(xlCellTypeVisible)
' Insert formulas
.FormulaR1C1 = "=IFERROR(INDEX('" & "[" & wbName & "]" & Replace(ws.Name, "'", "''") & "'!C11, MATCH(RC[-22],'" & "[" & wbName & "]" & Replace(ws.Name, "'", "''") & "'!C16, 0)), """")"
.Offset(, 1).FormulaR1C1 = "=IFERROR(INDEX('" & "[" & wbName & "]" & Replace(ws.Name, "'", "''") & "'!C13, MATCH(RC[-23],'" & "[" & wbName & "]" & Replace(ws.Name, "'", "''") & "'!C16, 0)), """")"
Application.Calculation = xlCalculationManual
' Convert formulas to values
.Value = .Value
.Offset(, 1).Value = .Offset(, 1).Value
End With
wbFile.Close SaveChanges:=False
End If
.AutoFilter.ShowAllData
End With
Set wbFile = Nothing
Set ws = Nothing
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
MsgBox "Payment Updated!"
End Sub
Function FileExists(ByVal FilePath As String) As Boolean
On Error Resume Next
FileExists = (Dir(FilePath) <> "")
On Error GoTo 0
End Function
Good luck.
Bookmarks