user2703472
user2703472

Reputation: 45

Excel VBA , code runs one one version of office but not in other?

I have the following code written on excel 2013 english and it works fine. but when i run it on excel 2007 german, it stuck on this line (if rngFrom.... 3rd line on the code) How can I solve this?

For j = 1 To rngFrom.Cells.Count
rngTo.Cells(j).Value = rngFrom.Cells(j)
If rngFrom.Cells(j).DisplayFormat.Interior.Color <> rngFrom.Cells(j).Interior.Color Then
    rngTo.Cells(j).Interior.Color = rngFrom.Cells(j).DisplayFormat.Interior.Color
End If
Next j

Upvotes: 0

Views: 631

Answers (1)

Siddharth Rout
Siddharth Rout

Reputation: 149315

but when i run it on excel 2007 german, it stuck on this line (if rngFrom.... 3rd line on the code) Any idea..how i can solve this?.

Range.DisplayFormat Property was added from xl2010+ onwards.

Please see THIS MSDN link.

Quote form that link (In case the link dies off):

enter image description here

EDIT:

I believe what you are trying to compare the conditional formatting color with the cells' interior color. If yes then you can use this code as well

For j = 1 To rngFrom.Cells.Count
    rngTo.Cells(j).Value = rngFrom.Cells(j)
    If rngFrom.Cells(j).FormatConditions(1).Interior.Color <> _
    rngFrom.Cells(j).Interior.Color Then
        rngTo.Cells(j).Interior.Color = _
        rngFrom.Cells(j).FormatConditions(1).Interior.Color
    End If
Next j

I am assuming that there is only one condition in the conditional formatting.

Upvotes: 1

Related Questions