I have coded a macro that appears to work (on some worksheets), but it seems rather heavy to me. Can you please take a look and see if changes can be made or a completely different macro that completes the same task. I am looking for a value "EUR" or "USD" in a number of specified columns. When either of the two values are found, the macro performs a calculation on adjacent cells and then changes the value of the original cell to AED.
Option Explicit
Sub Change_currency()
Const EUR_to_AED = 4.9
Const USD_to_AED = 3.64
Dim R As Long
Dim V1
Dim V2
Dim MyValue
Dim MyValue2
'Start at row 5
R = 5
While Cells(R, "K").Value <> ""
If Cells(R, "K").Value = "EUR" Then
Cells(R, "K").Activate
MyValue = 4.9
V1 = ActiveCell.Offset(0, -2).Value
V2 = ActiveCell.Offset(0, -3).Value
ActiveCell.Offset(0, -2).Value = MyValue * V1
ActiveCell.Offset(0, -1).Value = V1 * EUR_to_AED * V2
ActiveCell.Value = "AED"
End If
While Cells(R, "K").Value <> ""
If Cells(R, "K").Value = "USD" Then
Cells(R, "K").Activate
MyValue = 3.64
V1 = ActiveCell.Offset(0, -2).Value
V2 = ActiveCell.Offset(0, -3).Value
ActiveCell.Offset(0, -2).Value = MyValue2 * V1
ActiveCell.Offset(0, -1).Value = V1 * USD_to_AED * V2
ActiveCell.Value = "AED"
End If
'Next row
R = R + 1
Wend
End Sub
I am running into problems with some of the data on the sheets are not numerical and the macro throws an error. So how to ignore those errors?
Any help would be appreciated...