PDA

View Full Version : Solved: Macro to calculate only in cells filled with blue color



hunsnowboard
11-09-2010, 03:35 AM
I have a macro (I got it here actually, just made some small modifications) which is working brilliantly!

This is the code:

Sub EuroConverter()
Dim xchg As Single, ocel As Range
'Application.ScreenUpdating = False
xchg = 270.4885346
On Error Resume Next
For Each ocel In Selection
If ocel <> "" And IsNumeric(ocel.Value) Then
ocel.Value = Round(ocel.Value / xchg)
Else:
End If
Next
'Application.ScreenUpdating = True
End Sub

What it does, it changes the amounts in the selected cells. However I would like to upgrade it a bit, but I do not know if it is possible...

What I would like, is that the macro to work on the same principle, but only to execute the calculation in the cells which are filled with light blue color (color index = 34). Is it possible? I use excel 2007.
If you can, please try to help!

Thank you in advance!

hunsnowboard
11-09-2010, 03:57 AM
Thank you very much, but I figured out myself! :) Wohooo! Thanks!


Sub EuroConverter_color()
Dim xchg As Single, ocel As Range
'Application.ScreenUpdating = False
xchg = 270.4885346
On Error Resume Next
For Each ocel In Selection
If ocel <> "" And IsNumeric(ocel.Value) And ocel.Interior.ColorIndex = 34 Then
ocel.Value = Round(ocel.Value / xchg)
Else:
End If
Next
'Application.ScreenUpdating = True
End Sub