Results 1 to 1 of 1

VBA just stops in Windows 7 but not Windows XP...

Threaded View

  1. #1
    Registered User
    Join Date
    09-20-2012
    Location
    Edmonton, Canada
    MS-Off Ver
    Excel 2010
    Posts
    1

    Question VBA just stops in Windows 7 but not Windows XP...

    **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
    Last edited by TomCook; 09-20-2012 at 07:02 PM. Reason: Discovered it also failed in XP

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1