Convert macro between Excel versions: from 2010 to 2007 and 2003

mberon

New Member
Joined
Aug 20, 2013
Messages
3
Hi all,

I did a macro, it works well in Excel 2010, but in 2007 it triggers "Compile Error (Syntax Error)" on the first IF... THEN, I'd need have the macro working in 2007 and 2003, besides 2010:
Code:
Public Sub Color()
Dim DataRange As Range
Dim cell As Range
Set DataRange = Range("A1:ZZ500")
For Each cell In DataRange.Cells
    If (Not IsEmpty(cell)) And (cell.Value = "VERDE") Then
        cell.Select
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 5296274
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
cell.Value = ""
 
    End If
 
    If (Not IsEmpty(cell)) And (cell.Value = "AMARILLO") Then
        cell.Select
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 65535
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
cell.Value = ""
 
    End If
 
    If (Not IsEmpty(cell)) And (cell.Value = "NARANJA") Then
        cell.Select
   With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 49407
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
cell.Value = ""
 
    End If
    If (Not IsEmpty(cell)) And (cell.Value = "ROJO") Then
        cell.Select
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 255
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
cell.Value = ""
 
    End If
    If (Not IsEmpty(cell)) And (cell.Value = "VERDEAMARILLO") Then
        cell.Select
    With Selection.Interior
        .Pattern = xlPatternLinearGradient
        .Gradient.Degree = 135
        .Gradient.ColorStops.Clear
    End With
    With Selection.Interior.Gradient.ColorStops.Add(0)
        .Color = 65535
        .TintAndShade = 0
    End With
    With Selection.Interior.Gradient.ColorStops.Add(1)
        .Color = 5296274
        .TintAndShade = 0
    End With
cell.Value = ""
 
    End If
 
    If (Not IsEmpty(cell)) And (cell.Value = "VERDENARANJA") Then
        cell.Select
With Selection.Interior
        .Pattern = xlPatternLinearGradient
        .Gradient.Degree = 135
        .Gradient.ColorStops.Clear
    End With
    With Selection.Interior.Gradient.ColorStops.Add(0)
        .Color = 5296274
        .TintAndShade = 0
    End With
    With Selection.Interior.Gradient.ColorStops.Add(1)
        .Color = 49407
        .TintAndShade = 0
    End With
cell.Value = ""
 
    End If
 
    If (Not IsEmpty(cell)) And (cell.Value = "NARANJAROJO") Then
        cell.Select
    With Selection.Interior
        .Pattern = xlPatternLinearGradient
        .Gradient.Degree = 135
        .Gradient.ColorStops.Clear
    End With
    With Selection.Interior.Gradient.ColorStops.Add(0)
        .Color = 49407
        .TintAndShade = 0
    End With
    With Selection.Interior.Gradient.ColorStops.Add(1)
        .Color = 255
        .TintAndShade = 0
    End With
cell.Value = ""
 
    End If
Next
End Sub
_______________________________________________________

Anybody knows how to do this?

Thanks.
 
Last edited by a moderator:

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
You can't do gradient fills in 2003 so that code won't work.
 
Upvote 0
OK, but in Excel 2007? I said 2003 to have all options, but I think users will use Excel 2007..
 
Upvote 0
What's the actual error and on which specific line? None of those properties appear to be 2010 specific.
 
Upvote 0
It says: Compile Error: Syntax Error, in this line: If (Not IsEmpty(cell)) And (cell.Value = "VERDE") Then . In 2010, this macro works well.
 
Upvote 0
There's nothing about that line that shouldn't work in 2007 (or any other vba-enabled version) but the double test is fairly pointless:
Code:
If cell.Value = "VERDE" Then
would achieve the same thing.
 
Upvote 0
Hi, Just want to confirm if this has been resolved? I'm currently facing the same issues. I created a whole reporting dashboard in Excel 2010 that works with tables, graphs, changing values, etc. Did not realize that everyone else was using Excel 2007. I'm not a beginner but certainly not advanced vba programmer. Re-programming everything will take me ages...
 
Upvote 0
What issue are you facing specifically? There is no guarantee that code written in 2010 will be backward compatible.
 
Upvote 0
try replacing your variable name "cell" with "cel"

cell may be a reserved word


another thing to try

in your code highlight cell.Value right click on it and select "add watch" .... click ok

do same for IsEmpty(cell)

then singlestep through code using F8 and watch the two values in "watch window"

see if the values are as expected isempty(cell) should result in true-false, cell.value should be a valid value (numeric or text)
 
Last edited:
Upvote 0
What issue are you facing specifically? There is no guarantee that code written in 2010 will be backward compatible.

Can I just create a separate thread? Would not want to create noise in this one... Maybe facing similar issues but for completely different purpose...

Will create new post tomorrow and try to attach my code (quite long though).
 
Upvote 0

Forum statistics

Threads
1,223,714
Messages
6,174,052
Members
452,542
Latest member
Bricklin

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