**UPDATE**
This actuall does fail in XP as well, after a bit more testing. So confused.
---
Hey folks,
So I've been scouring the internet since yesterday to try and figure out what the deal is with this, with no success. I have some code that, when run on my Windows XP machine in Excel 2010, executes flawlessly. On my Windows 7 (main) machine, however, when I get to any line that involves changing the Interior of a cell, the code executes that line, and then simply ceases. No error message, no nothing, the macro just stops running. At first I thought it was a problem with trying to tell a cell to be formatted in a way in which it was already formatted (I had had this issue with trying to tell a cell to have .NumberFormat = "$#,##0" when it already had that format), so I build in some if statements, which helped with the number formatting but now do not help on the following code:
Private Sub FillRangeInterior(r As Range, c As String, Optional comm As String)
Dim pat
Dim pci
Dim col
Dim tcol
Dim tas
Dim ptas
Dim x
Select Case UCase(Left(c, 1))
Case "R":
pat = xlSolid
pci = xlAutomatic
col = 255
tas = 0
ptas = 0
Case "Y":
pat = xlSolid
pci = xlAutomatic
col = 65535
tas = 0
ptas = 0
Case "G":
pat = xlSolid
pci = xlAutomatic
col = 5296274
tas = 0
ptas = 0
Case "B":
pat = xlSolid
pci = xlAutomatic
tcol = xlThemeColorAccent5
tas = 0.599993896298105
ptas = 0
Case "1":
pat = xlSolid
pci = xlAutomatic
tcol = xlThemeColorAccent5
tas = 0.799981688894314
ptas = 0
Case "2":
pat = xlSolid
pci = xlAutomatic
tcol = xlThemeColorAccent3
tas = 0.799981688894314
ptas = 0
Case "3":
pat = xlSolid
pci = xlAutomatic
tcol = xlThemeColorAccent4
tas = 0.799981688894314
ptas = 0
Case Default:
UnfillRangeInterior r
GoTo DoneLabel
End Select
DoEvents
On Error GoTo 0
For Each x In r.Cells
If x.Interior.Pattern <> pat Then x.Interior.Pattern = pat
If x.Interior.PatternColorIndex <> pci Then x.Interior.PatternColorIndex = pci
If x.Interior.Color <> col And col <> 0 Then x.Interior.Color = col
If x.Interior.ThemeColor <> tcol And tcol <> 0 Then x.Interior.ThemeColor = tcol
If x.Interior.TintAndShade <> tas Then x.Interior.TintAndShade = tas
If x.Interior.PatternTintAndShade <> ptas Then x.Interior.PatternTintAndShade = ptas
Next x
DoneLabel:
If comm <> "" Then r.AddComment comm
End Sub
It's ugly, I know. It was a lot cleaner when I had first written it; this is the result of me trying various means of solving the issue, but to no end. Any place in that code when I try to assign a value to x.Interior.<something>, the code will do so, and then just stop. Other than simply finishing this project on my XP machine (which isn't really a viable long-term solution as we're eventually all moving to Windows 7), can anyone offer some insight or suggestions as to what is going on and how to fix it?
Thanks,
Tom
Bookmarks