I have a simple macro working for the below table:
A B C D
[TABLE="width: 500"]
<tbody>[TR]
[TD]Transport[/TD]
[TD]Amount[/TD]
[TD]Currency[/TD]
[TD]USD[/TD]
[/TR]
[TR]
[TD]Flight to Narita[/TD]
[TD]300[/TD]
[TD]USD[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Shinkanzen[/TD]
[TD]13,080[/TD]
[TD]YEN[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
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