Lookup, match, change cells, then multiply across tabs VBA

Joined
Dec 18, 2016
Messages
3
okay i just started using VBA/macros today and im pretty pleased with my progress so far :) but hit a brick wall i think above my pay grade...

not looking for a bailout i'd like to understand this for the future. My job could really use these....

Data tab called "Quotation Tool":

tradeproductdatepercurrencycostMSRSSR
NWoceandec-12kgUSD200400450
SWoceandec-12kgCNY245
SWoceande-12kgHKD489

<tbody>
</tbody>


then i have a currency conv tab called "Currencies" (refreshed web data):

currency1USDinv.1USD
CNY6.91.4
HKD7.11.2

<tbody>
</tbody>

what i want to do: search the column for currency on data tab, find "CNY" or "HKD" or another currency. when it finds it i want to go corresponding "MSR" column cell and multiply that value by the cell in the "currencies" tab corresponding with the right currecy conversion then put result in that cell on the data tab.

I have been working on this for about 5 hours peicing together different codes from threads all over. what i have looks too basic for what i need:

Code:
    Sub CurrencyConv()
    '
    ' CurrencyConv Macro
    '
    
    '
        Dim Rng As Range
        On Error Resume Next
        With ActiveSheet.UsedRange
            Set Rng = .Range("L3:L" & .Rows(.Rows.Count).Row)
        End With
        If Range(Rng) = "CNY" Then
            ActiveCell.Offset(0, 3).Select
        End If
        If Rng = "CNY" Then
            ActiveCell.Formula = "=(ActiveCell.Value*Worksheets(Currencies)$C$12)"
        End If
    End Sub
I actually managed to run macros across workbooks using different lookups and replacements but this is stumping me. your thoughts are appreciated!
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Hi

Try this code:


LateralThinker

Code:
 Sub CurrencyConv()
 
 Dim shtCur           As Worksheet
 Dim shtQuoat         As Worksheet
 Dim rngCurr          As Range
 Dim rngCurrRate      As Range
 Dim rngCell          As Range
 Dim dblTargetCurRate As Double
 
 Set shtCur = Worksheets("Currencies")
 Set shtQuoat = Worksheets("Quoatation Tool")
 Set rngCurr = shtQuoat.Range("L2:L" & shtQuoat.Cells(Rows.Count, "L").End(xlUp).Row)
 Set rngCurrRate = shtCur.Range("A2:C" & shtCur.Cells(Rows.Count, "A").End(xlUp).Row)
 Set rngCurrTarget = shtCur.Range("A2")
  
 For Each rngCell In rngCurr
     
     If rngCell.Value <> "USD" Then
        dblTargetCurRate = Application.VLookup(rngCell.Value, rngCurrRate, 3, False)
        rngCell.Offset(0, 3).FormulaR1C1 = "=RC14*" & dblTargetCurRate
     End If
 
 Next rngCell
 
End Sub
 
Upvote 0
Lateral,

sorry for the delays i am just getting a second to look at this again. i input the code and adjusted as i altered the columns a bit. but when running i got a "mismatch" "13" runtime error for:

dblTargetCurRate = Application.VLookup(rngCell.Value, rngCurrRate, 3, False)

is it because rngCell is not "Set"?

seems to be the onl
 
Upvote 0

Forum statistics

Threads
1,215,734
Messages
6,126,542
Members
449,316
Latest member
sravya

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