Find A Value Copy to Cell and replace Text

Mpotten

New Member
Joined
Apr 2, 2015
Messages
12
Hi All

I need to upgrade this macro that I have written using the Macro Record function.

The basics are that I wish to look up the text EUR in column G and every time if finds that value Copy across to the cell to the left in Column F and Delete the text EUR leaving just the numerical value. The next step is to delete the original cell insert the exchange value into the row on Column I and perform the calculation to give a dollar value in the starting cell in column G.

I have been successful with the calculations and the copying but currently it only works for a single cell and row not the whole data set.

here is the code
Code:
Sub Euro_Correction()'
' Euro_Correction Macro
'
' Keyboard Shortcut: Option+Cmd+Shift+E
'
    
    Columns("G:G").Select
    Selection.Find(What:="EUR", After:=ActiveCell, LookIn:=xlFormulas, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False).Activate
    Range("G36").Select
    Selection.Copy
    Range("F36").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    ActiveCell.Replace What:="EUR", Replacement:="", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False
    Cells.Find(What:="EUR", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
        xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False) _
        .Activate
    Selection.ClearContents
    ActiveCell.FormulaR1C1 = "=SUM(RC[-1]/RC[2])"
    Range("H36").Select
    ActiveCell.FormulaR1C1 = ""
    Range("I36").Select
    ActiveCell.FormulaR1C1 = "0.58026923"
End Sub

and here is a sample data set.

ABCDEFGHIJ
Co./Last NameDateItem NumberQtyDesc.EuroPriceTotalForexSalesRep
cust 11/3/1512341$3000
cust 11/3/1512351$4000
cust 21/3/1512362$5000
cust 21/3/1512371$6000
cust 34/3/1512343EUR100.58926
cust 34/3/1512351EUR200.58926
cust 45/3/1512361EUR300.58926
cust 45/3/1512374EUR300.58926
cust 55/3/1512382$7000

<tbody>
</tbody>
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Hi Mpotten,


As your have done it all, why don't you search internet for "VBA Loops" and update your code.


Regards,
DILIPandey
 
Upvote 0
Thanks Dilipandey

I have just realised that i will also need to add in code so that i can get the macro to find the last cell with data to set the total range to work with.

I can use column A as this will always have uninterrupted data from the top of the Data set to the Bottom.

Code:
Range ("A2").select
selection.end(xldown).Select
LastRow = Selection.Row
 
Upvote 0
If I have understood your code correctly, the following macro should do what you want your code to do for every row. Of course, test it on a copy of your actual workbook while you determine that the code does, in fact, do what you intend it to.
Code:
Sub Euro_Correction() '
  [B][COLOR="#0000FF"]Const ConversionRate As Double = 0.58026923[/COLOR][/B]
  Dim LastRow As Long
  LastRow = Cells(Rows.Count, "G").End(xlUp).Row
  Range("F2:F" & LastRow) = Evaluate(Replace("IF(LEFT(G2:G#,3)=""EUR"",0+MID(G2:G#," & _
                            "4,99),IF(F2:F#="""","""",F2:F#))", "#", LastRow))
  With Range("F2:F" & LastRow).SpecialCells(xlConstants)
    .Offset(, 1).Formula = "=F" & .Row & "/I" & .Row
  End With
  Range("I2:I" & LastRow) = Evaluate(Replace("IF(LEN(F2:F#)," & _
                            ConversionRate & ",I2:I#)", "#", LastRow))
End Sub

Note that I put the conversion rate in a statement at the top of the code so you can find it more easily in case you have to change it later on. Also, verify that I handled this conversion factor correctly with respect to your existing data in case it does change in the future.
 
Last edited:
Upvote 0
HI i know that this thread is now old and the above code has been working great for me.

I have now come across a small issue where this no longer works if when the code searches of "EUR" and does not find this string it causes the macro to report an error and not run. I have other sales that are in $ which still need to be addressed as part of the sales process.
 
Upvote 0
i have not replaced the or modified the code in any way
Euro%20Code.png
 
Upvote 0
i have not replaced the or modified the code in any way
Euro%20Code.png
We cannot see an image which is located on your computer. Help us this way... post a table of value where the code I posted in Message #4 fails (the quick test I did didn't fail).
 
Upvote 0

Forum statistics

Threads
1,215,136
Messages
6,123,249
Members
449,093
Latest member
Vincent Khandagale

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