Results 1 to 9 of 9

Run-time error '9': Subscript out of range

Threaded View

  1. #1
    Registered User
    Join Date
    07-02-2014
    Location
    Branson, MO
    MS-Off Ver
    365
    Posts
    8

    Run-time error '9': Subscript out of range

    [SOLVED]I am trying to run the following code out of my personal workbook. It works on any new workbook I create, but not on any previous workbook (still xlsx) that I open.

    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #3 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer

    Sub HighlightRow()
    ' Highlight the entire row of the cell selected
    
    Application.ScreenUpdating = False
     
    ' Remove the Conditional formatting and "screen updating" code from the active sheet (toggle off)   
        For i = 1 To Cells.FormatConditions.Count    ' loops through all conditional formatting rules
            If Cells.FormatConditions(i).Formula1 = "=CELL(""row"")=ROW()" Then
                Cells.FormatConditions(i).Delete
                With ActiveWorkbook.VBProject.VBComponents(ActiveSheet.Name).CodeModule
                    On Error GoTo ExitS
                    .DeleteLines 1, [5]
                End With
    ExitS:
                Exit Sub
                On Error Resume Next
            End If
        Next i
     
    ' if the above rule is not found, inserts rule and "screen updating" code into activesheet (toggle on)   
        Cells.FormatConditions.Add Type:=xlExpression, Formula1:= _
            "=CELL(""row"")=ROW()"
        Cells.FormatConditions(Cells.FormatConditions.Count).SetFirstPriority
        With Cells.FormatConditions(1).Interior
            .PatternColorIndex = xlAutomatic
            .ThemeColor = xlThemeColorDark1
            .TintAndShade = -0.14996795556505
        End With
        Cells.FormatConditions(1).StopIfTrue = False
        
        With ActiveWorkbook.VBProject.VBComponents(ActiveSheet.Name).CodeModule
            .InsertLines Line:=.CreateEventProc("SelectionChange", "Worksheet") + 1, _
                         String:=vbCrLf & "    application.screenupdating = True"
        End With
        Application.VBE.MainWindow.Visible = False
    
    Application.ScreenUpdating = True
    
    End Sub
    Sorry if this is a bit messy. Any help would be appreciated.
    Last edited by ndsutherland; 10-27-2014 at 12:27 PM. Reason: add narration

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Run-time error '9': Subscript out of range
    By chergian in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-06-2014, 02:40 AM
  2. [SOLVED] Run-time error '9': subscript out of range - error occurs on multiple computers except one
    By BrettE in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-06-2014, 11:19 PM
  3. [SOLVED] Run Time Error 9 - Subscript out of range
    By kushmakarsharma in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-25-2012, 08:02 AM
  4. VB Run-time error '9'; Subscript out of range
    By lisabethvw in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-29-2009, 03:49 AM
  5. run-time error '9': Subscript out of range
    By AccessHelp in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-30-2005, 01:05 PM

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