I have a simple macro working for the below table:
A B C D
Transport | Amount | Currency | USD |
Flight to Narita | 300 | USD | |
Shinkanzen | 13,080 | YEN |
<tbody>
</tbody>
If Currency in column "C" is YEN, the macro convert the amount in USD in column "D", otherwise, if the currency is "USD", the macro just copy the value from B to D.
What I did, however, was a very simple macro. Instead of repeating the lines each time as I did (first verifying if the value for C1 is yen or usd; then verifying C2; etc.), is there an easy
Thanks a lot !
Code:
Sub test()
If Sheets("Data").Range("C2").Value = "USD" Then
Sheets("Data").Range("D2").Value = Sheets("Data").Range("B2").Value
ElseIf Sheets("Data").Range("C2").Value = "YEN" Then
Sheets("Data").Range("D2").Value = Sheets("Data").Range("B2").Value*0.0089
Else: Sheets("Data").Range("C2").Value = "currency not USD nor YEN”
End If
If Sheets("Data").Range("C3").Value = "USD" Then
Sheets("Data").Range("D3").Value = Sheets("Data").Range("B3").Value
ElseIf Sheets("Data").Range("C3").Value = "YEN" Then
Sheets("Data").Range("D3").Value = Sheets("Data").Range("B3").Value*0.0089
Else: Sheets("Data").Range("C3").Value = "currency not USD nor YEN”
End If
End Sub