+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    10-23-2009
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    39

    Question Find last row of A:A with data and stop

    I have a while loop to color my rows down to row 2000 but all the time color way more than needed.

    I like to change the while loop or replace with better code statement that will see last row of (A:A) that has data and stop there, then to keep color code rows to 2000.


    Code:
    Sub UpdateKitListColor()
    '
    ' UpdateKitListColor Macro
    ' Update Color for Kit List parts
        
        Dim LRow As Integer
        Dim ACell As String
        Dim LCell As String
        Dim LColorCells As String
        Dim LColorCellsA2I As String
        Dim LColorCellsJ2O As String
        Dim LColorCellsP2T As String
        Dim LColorCellsU2A0 As String
        Dim LColorCellsAP2BU As String
        
        'Start at row 3
        LRow = 3
       
        ' Select sheet to color code 
        Sheets("BOM").Select
      
        'Update row colors for the first 2000 rows
        While LRow < 2000
    
            ACell = "A" & LRow
            'Items in Column "C" and the present LRow
            LCell = "H" & LRow
            
            'Color will changed in columns A to K
            LColorCells = "A" & LRow & ":" & "BU" & LRow
            LColorCellsA2I = "A" & LRow & ":" & "I" & LRow
            LColorCellsJ2O = "J" & LRow & ":" & "O" & LRow
            LColorCellsP2T = "P" & LRow & ":" & "T" & LRow
            LColorCellsU2AO = "U" & LRow & ":" & "AO" & LRow
            LColorCellsAP2BU = "AP" & LRow & ":" & "BU" & LRow
            
            Select Case Left(Range(LCell).Value, 6)
                
                'Set row color to Yellow
                Case "KT"
                    Range(LColorCells).Interior.ColorIndex = 15
                    Range(LColorCells).Interior.Pattern = xlSolid
                                  
                'Default all other rows to no color
                Case Else
                    Rows(LRow & ":" & LRow).Select
                    'Range(LColorCells).Interior.ColorIndex = xlNone
                    'WHITE COLUMN A-I
                    'Range(LColorCellsA2I).Interior.ColorIndex = 2
                    Range(LColorCellsA2I).Interior.Pattern = xlNone
                    'LIGHT BLUE COLUMN J-O
                    Range(LColorCellsJ2O).Interior.ColorIndex = 34
                    Range(LColorCellsJ2O).Interior.Pattern = xlSolid
                    'LIGHT GREEN COLUMN P-T
                    Range(LColorCellsP2T).Interior.ColorIndex = 35
                    Range(LColorCellsP2T).Interior.Pattern = xlSolid
                    'LIGHT PINK COLUMN U-AO
                    Range(LColorCellsU2AO).Interior.ColorIndex = 40
                    Range(LColorCellsU2AO).Interior.Pattern = xlSolid
                    'WHITE COLUMN AP-BU
                    'Range(LColorCellsAP2BU).Interior.ColorIndex = 2
                    Range(LColorCellsAP2BU).Interior.Pattern = xlNone
                
            End Select
                  
            LRow = LRow + 1
            
        Wend
         
        Range("A1").Select
         
        'Sheets("TOOLS").Select
        
    End Sub
    Last edited by MBCMDR; 11-11-2009 at 02:54 AM. Reason: Added full code

  2. #2
    Forum Moderator ConneXionLost's Avatar
    Join Date
    03-11-2009
    Location
    Victoria, Canada
    MS-Off Ver
    2003 & 2010
    Posts
    1,798

    Re: Find last row of A:A with data and stop

    So, this isn't an Access question?
    Docendo discimus.

    Please consider:
    • Thanking those who helped you. Click the reputation icon in the contributor's post and add Reputation.
    • Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  3. #3
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,379

    Re: Find last row of A:A with data and stop

    Thread moved...

  4. #4
    Registered User
    Join Date
    10-23-2009
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    39

    Re: Find last row of A:A with data and stop

    Sorry I must have posted in wrong group as also doing an Access project but it doinmg much better than my excel macros LOL....

    MB

  5. #5
    Registered User
    Join Date
    10-23-2009
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    39

    Re: Find last row of A:A with data and stop

    I first posted in wrong fourm and this seem to have gotten lost because of me please see attached Sample of the color code.

    Marco on Worksheet "TOOLS" and controls color on worksheet "BOM"

    When you click the macro it color codes rows 3 - 2000 I just like it to color code the rows with data (A3:A) as each BOM project has its own parts kit and number of items.

    MB

    Figure it out fairly easy was over looking first idea..
    Here the change I did in the macro
    Code:
        Dim Rng As Range
        
        'Start at row 3
        LRow = 3
         
        Sheets("BOM").Select
      
      With Sheets("BOM")
      Set Rng = .Range("A3", .Range("A" & Rows.Count).End(xlUp))
      End With
      
        'Update row colors for the first 2000 rows
        While LRow < Rng.Count + 3
    MB
    Attached Files Attached Files
    Last edited by MBCMDR; 11-11-2009 at 02:56 AM.

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.2.0