I have the below code, but for some reason, the "myRng.Offset(LastRow, 0).Value" is "Empty" and therefore the calculations are not performed and I receive the Overflow error due to a divide by 0.
Dim ws1 As Worksheet, wb1 As Workbook, LastRow As Long, LastCol As Long, myCol As String
Dim RowTest As Long, myRng As Range, FXwb As Workbook, ws2 As Worksheet
Dim FXrng As Range, FXval As Variant, Cur As String
LastRow = ws1.Range("B" & Rows.Count).End(xlUp).Row
Set myRng = Range("1:1").Find("LocalCurrency")
If myRng.Offset(LastRow, 0).Value <> "USD" Then
Cur = myRng.Offset(LastRow, 0).Value
FXwb.Activate
Set FXrng = Range("C:C").Find(Cur)
FXval = FXrng.Offset(0, 1).Value
wb1.Activate
Set myRng = Range("1:1").Find("Commitment (USD)")
myRng.Offset(LastRow, 0).Value = myRng.Offset(LastRow, -1).Value / FXval
Set myRng = Range("1:1").Find("Funding (USD)")
myRng.Offset(LastRow, 0).Value = myRng.Offset(LastRow, -1).Value / FXval
Set myRng = Range("1:1").Find("Adjusted Valuation (USD)")
myRng.Offset(LastRow, 0).Value = myRng.Offset(LastRow, -1).Value / FXval
Else
Set myRng = Range("1:1").Find("Commitment (USD)")
myRng.Offset(LastRow, 0).Value = myRng.Offset(LastRow, -1).Value
Set myRng = Range("1:1").Find("Funding (USD)")
myRng.Offset(LastRow, 0).Value = myRng.Offset(LastRow, -1).Value
Set myRng = Range("1:1").Find("Adjusted Valuation (USD)")
myRng.Offset(LastRow, 0).Value = myRng.Offset(LastRow, -1).Value
End If
New edit - changed FXval from Long to Variant - code works perfectly now! thanks to Jeeped for the answer and Chris Neilson for the suggestions
Findis problematic. Because you haven't specified anything other than theWhatparameter, you might not get the results you expect. The settings forLookIn,LookAt,SearchOrder, andMatchByteare saved each time you use this method (either the user in Excel or with VBA). If you do not specify values for these arguments the next time you call the method, the saved values are used. Also, you are using implicit references to theActiveSheet