PDA

View Full Version : Macro checking if currency change is right



hunsnowboard
10-28-2010, 04:04 AM
Hi Everybody! I have the following problem. I have two files (file A and file B). The content of the files is almost identical (everything is in the same place, same cells) the only difference is that file A has its values in Euros file B has its values in USD. Both files have many sheets all with many numbers.

Is it possible to have a macro which will check (with a given currency rate) if the values are correct? So basically the macro should first check if in workbook A that a cell contains a numerical value (not empty, not text, not formula just a numerical value) and then and if it is a numerical value.... then check the same cell in workbook B and compare it with the currency rate. So if the given currency rate is 1,5 and file A has the value 10 in Sheet1, Cell A1..then the macro should check the value in file B Sheet2, Cell A1 and the value should be 15. If the value is correct then the macro should move to the next cell and so on till finds an incorrect value. In case of incorrect value the macro should display a message box and locating the address of the incorrect cell and stop.
If everything is correct then at the end should display a message box that every value is good and it has finished.

Excel version: 2007

Is it possible to make this macro?
Thank you in advancem for your help!

Bob Phillips
10-29-2010, 03:22 AM
This is off the top as a starter



Public Sub CheckCurrencies()
Const EX_RATE As Double = 1.5
Dim wb1 As Workbook
Dim wb2 As Workbook
Dim sh As Worksheet
Dim cell As Range
Dim cell2 As Range
Dim msg As String

Set wb1 = Workbooks("WB Euros.xls")
Set wb2 = Workbooks("WB Dollars.xls")

For Each sh In wb1.Worksheets

msg = ""
For Each cell In sh.UsedRange.Cells

If cell.Value2 <> "" Then

If IsNumeric(cell.Value2) Then

Set cell2 = wb2.Worksheets(sh.Name).Cells(cell.Address)
If cell.Value2 <> cell2.Value2 * EX_RATE Then

msg = msg & vbTab & cell.Address & ": " & cell.Value2 & ", " & cell2.Value
End If
End If
End If
Next cell

If msg <> "" Then MsgBox sh.Name & vbNewLine & msg
Next sh
End Sub

hunsnowboard
10-29-2010, 04:18 AM
Thank you a lot! I'll work on it, and feedback the results! Thanks again and have a nice weekend!