Cost Value Calculator

3d4d5c

New Member
Joined
Feb 8, 2019
Messages
10
Cost value (Local currency)CurrencyCost value
500SGD
3664EUR

<tbody>
</tbody>

So I'm stuck in a situation whereby, I'm supposed to convert the cost value (local currency) into cost (in USD).
I had made a button to run the VBA Macro to calculate the values and paste back into the table.

Here's my coding:

Sub Costvalue()
Dim Country As String, Cost As Double, total As Double, xrate As Double
Dim r As Integer, c As Integer

r = 9
c = 10

'Cell(9,10) is at value 500.'

Country = ActiveCell(r, c)

Do While Country <> ""

If Country = "SGD" Then
xrate = 0.74
ElseIf Country = "EUR" Then
xrate = 1.13
ElseIf Country = "CHF" Then
xrate = 1
ElseIf Country = "GBP" Then
xrate = 1.29
End If

Cost = ActiveCell(r, c - 1).Value
Range(r, c + 1).Value = Cost * xrate 'here is the error'

r = r + 1
c = c + 1

Loop
End Sub
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Code:
Maybe this....UNTESTED
Sub Costvalue()
Dim Country As String, Cost As Double, total As Double, xrate As Double
Dim r As Integer, c As Integer
r = 9
c = 10
'Cell(9,10) is at value 500.'
Country = Cells(r, c)
Do While Country <> ""
    If Country = "SGD" Then
    xrate = 0.74
    ElseIf Country = "EUR" Then
    xrate = 1.13
    ElseIf Country = "CHF" Then
    xrate = 1
    ElseIf Country = "GBP" Then
    xrate = 1.29
    End If
    Cost = Cells(r, c - 1).Value
    Cells(r, c + 1).Value = Cost * xrate 'here is the error'
r = r + 1
c = c + 1
Loop
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,431
Members
448,961
Latest member
nzskater

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top