+ Reply to Thread
Results 1 to 2 of 2

Cannot find range in Sub Colour_coding script

Hybrid View

MakkyD Cannot find range in Sub... 12-16-2013, 11:25 AM
HaHoBe Re: Cannot find range in Sub... 12-16-2013, 02:12 PM
  1. #1
    Registered User
    Join Date
    04-22-2013
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    6

    Cannot find range in Sub Colour_coding script

    I have attached a report which contains a colour coding script was written by an ex colleague. The problem is when running the macro it stops at line 89. I have had to extend this list beyond line 89. I cannot find the "range" within the VBA which identifies what the range selected should be. spent hours trying to work it out and am now stumped.


    Before anyone suggests I use conditional formatting, this has to work on Excel 2003 which sadly is limited to 3 conditions.
    Attached Files Attached Files
    Last edited by MakkyD; 12-16-2013 at 11:43 AM. Reason: Had to edit sensitive data in attachment

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Cannot find range in Sub Colour_coding script

    Hi, MakkyD,

    the last loop starts with
    z = 6
    Do While z < 90
    You should try using a more specific way in getting the last row and then use a For lngRow = 44 to LngLR
    lngLR = Range("A") & Rows.Count).End(xlUp).Row
    Sub Colour_coding()
    Dim x As Long, y As Long, z As Long
    
    x = 6
    Do While x < 39
      If Cells(x, 6) <> 0 Then
        With Cells(x, 10).Interior
          .Pattern = xlSolid
          .PatternColorIndex = xlAutomatic
        End With
      ElseIf Cells(x, 12) = "a" Then
        With Cells(x, 10).Interior
          .Pattern = xlSolid
          .PatternColorIndex = xlAutomatic
          .ColorIndex = 16
        End With
      ElseIf Cells(x, 12) = "x" Then
        With Cells(x, 10).Interior
          .Pattern = xlSolid
          .PatternColorIndex = xlAutomatic
          .Color = 15773696
        End With
      ElseIf Cells(x, 12) = 1 Then
        With Cells(x, 10).Interior
          .Pattern = xlSolid
          .PatternColorIndex = xlAutomatic
          .Color = 3407718
        End With
      ElseIf Cells(x, 12) = 2 Then
        With Cells(x, 10).Interior
          .Pattern = xlSolid
          .PatternColorIndex = xlAutomatic
          .Color = 10092543
        End With
      ElseIf Cells(x, 12) = 3 Then
        With Cells(x, 10).Interior
          .Pattern = xlSolid
          .PatternColorIndex = xlAutomatic
          .ColorIndex = 46
        End With
      ElseIf Cells(x, 12) = 4 Then
        With Cells(x, 10).Interior
          .Pattern = xlSolid
          .PatternColorIndex = xlAutomatic
          .Color = 49407
        End With
      ElseIf Cells(x, 12) = 5 Then
        With Cells(x, 10).Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 13395711
        End With
      End If
      x = x + 1
    Loop
    
    y = 44
    Do While y < 86
    
      If Cells(y, 12) = "a" Then
        With Cells(y, 10).Interior
          .Pattern = xlSolid
          .PatternColorIndex = xlAutomatic
        End With
      ElseIf Cells(y, 12) = 1 Then
        With Cells(y, 10).Interior
          .Pattern = xlSolid
          .PatternColorIndex = xlAutomatic
          .Color = 3407718
        End With
      ElseIf Cells(y, 12) = 2 Then
        Cells(y, 10).Select
        With Cells(y, 10).Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 10092543
        End With
      ElseIf Cells(y, 12) = 3 Then
        With Cells(y, 10).Interior
          .Pattern = xlSolid
          .PatternColorIndex = xlAutomatic
        End With
      ElseIf Cells(y, 12) = 4 Then
        With Cells(y, 10).Interior
          .Pattern = xlSolid
          .PatternColorIndex = xlAutomatic
          .Color = 49407
        End With
      ElseIf Cells(y, 12) = 5 Then
        Cells(y, 10).Select
        With Cells(y, 10).Interior
          .Pattern = xlSolid
          .PatternColorIndex = xlAutomatic
          .Color = 13395711
        End With
      End If
      y = y + 1
    Loop
    
    z = 6
    Do While z < 90
      If Cells(z, 8) <> 0 Then
        Cells(z, 13).Select
        With Cells(z, 13).Interior
          .Pattern = xlSolid
          .PatternColorIndex = xlAutomatic
        End With
      ElseIf Cells(z, 15) = "a" Then
        With Cells(z, 13).Interior
          .Pattern = xlSolid
          .PatternColorIndex = xlAutomatic
          .ColorIndex = 16
        End With
      ElseIf Cells(z, 15) = 1 Then
        With Cells(z, 13).Interior
          .Pattern = xlSolid
          .PatternColorIndex = xlAutomatic
          .Color = 3407718
        End With
      ElseIf Cells(z, 15) = 2 Then
        With Cells(z, 13).Interior
          .Pattern = xlSolid
          .PatternColorIndex = xlAutomatic
          .Color = 10092543
        End With
      ElseIf Cells(z, 15) = 3 Then
        With Cells(z, 13).Interior
          .Pattern = xlSolid
          .PatternColorIndex = xlAutomatic
          .ColorIndex = 46
        End With
      ElseIf Cells(z, 15) = 4 Then
        With Cells(z, 13).Interior
          .Pattern = xlSolid
          .PatternColorIndex = xlAutomatic
          .Color = 49407
        End With
      ElseIf Cells(z, 15) = 5 Then
        Cells(z, 13).Select
        With Cells(z, 13).Interior
          .Pattern = xlSolid
          .PatternColorIndex = xlAutomatic
          .Color = 13395711
        End With
      ElseIf Cells(z, 15) = "x" Then
        Cells(z, 13).Select
        With Selection.Interior
          .Pattern = xlSolid
          .PatternColorIndex = xlAutomatic
          .Color = 15773696
        End With
      End If
      z = z + 1
    Loop
    End Sub
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Find and replace script
    By grandmastr in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-26-2010, 12:59 PM
  2. VBA find script
    By nygwnj in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-11-2009, 10:36 PM
  3. Find and replace script
    By mambotech in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-28-2009, 05:07 AM
  4. VBA Script. Find & Replace.
    By denis.samoilov in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-07-2008, 11:14 AM
  5. [SOLVED] Script to find the word END
    By Gary Prescott via OfficeKB.com in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-18-2005, 11:20 AM

Tags for this Thread

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