Consulting

Results 1 to 12 of 12

Thread: Solved: to extend the coloring

  1. #1
    VBAX Regular
    Joined
    Apr 2010
    Posts
    39
    Location

    Talking Solved: to extend the coloring

    hello, now the color is until column H, i need to extend the color until column Z, as i got a loy of sheets like this, so i need a macro to do this for me. Is it possible? thank you!

  2. #2
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Not well tested, and not utterly sure that the .UsedRange would faithfully pick up interior, but it is what I could think of...

    Sub exa()
    Dim wks As Worksheet
    Dim rngColor As Range
    Dim rCell As Range
        
        For Each wks In ThisWorkbook.Worksheets
            
            Set rngColor = wks.Range(wks.Cells(1, 1), _
                                     wks.Cells(wks.UsedRange.SpecialCells(xlCellTypeLastCell).Row, 1))
            
            For Each rCell In rngColor
                If Not rCell.Interior.ColorIndex = xlColorIndexNone Then
                    rCell.Resize(, 26).Interior.ColorIndex = rCell.Interior.ColorIndex
                End If
            Next
        Next
    End Sub
    Mark

  3. #3
    VBAX Regular
    Joined
    Apr 2010
    Posts
    39
    Location
    hi, gto.
    thank you for the help. But i got my own loop to run through every sheet i need, so i need to insert your code to my loop, so i edit your code to

    [VBA]
    'Dim wks As Worksheet
    Dim rngColor As Range
    Dim rCell As Range

    ' For Each wks In ThisWorkbook.Worksheets

    ' Set rngColor = wks.Range(wks.Cells(1, 1), _
    wks.Cells(wks.UsedRange.SpecialCells(xlCellTypeLastCell).Row, 1))
    Set rngColor = Range(Cells(1, 1), Cells(UsedRange.SpecialCells(xlCellTypeLastCell).Row, 1))
    For Each rCell In rngColor
    If Not rCell.Interior.ColorIndex = xlColorIndexNone Then
    rCell.Resize(, 26).Interior.ColorIndex = rCell.Interior.ColorIndex
    End If
    Next
    ' Next
    [/VBA]i changed it lthis way, dont know where is the problem, got error says "Object required". Can help with this?? Thank you!

  4. #4
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,055
    Location
    You have set rngcolor twice. Which one do you need?
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  5. #5
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    I see that you have the first Set REM'd. Why is the active Set not qualified?

  6. #6
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Quote Originally Posted by GTO
    I see that you have the first Set REM'd. Why is the active Set not qualified?
    There is also a linebreak in that line, so it is part REM'D.

    I don't follow the explanation.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  7. #7
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Hi Malcom,

    Quote Originally Posted by mdmackillop
    There is also a linebreak in that line, so it is part REM'D.
    But there's a line continuation character as well; just not picked up by the tags.

    Quote Originally Posted by mdmackillop
    I don't follow the explanation.
    I simply questioned (or more accurately, was trying to question) this bit:

    [vba]Set rngColor = Range(Cells(1, 1), Cells(UsedRange.SpecialCells(xlCellTypeLastCell).Row, 1)) [/vba]

    W/O seeing how the code is incorporated into the loop, it is of course a guess, but I was suspecting that Range/Cells/UsedRange need qualified. My bad, I was certainly not very clear.

    Mark

  8. #8
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Mark,
    It was the OP I was failing to follow!
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  9. #9
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    ACK!

    Sorry my friend, still blonde and a long shift...

  10. #10
    VBAX Regular
    Joined
    Apr 2010
    Posts
    39
    Location
    Hi, GTO. sorry for making you all confused. maybe you could just remove the sheets loop part for me, so that i could just insert your code into my loop.......Thank you

  11. #11
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Quote Originally Posted by Yjmmay34
    Hi, GTO. sorry for making you all confused. maybe you could just remove the sheets loop part for me, so that i could just insert your code into my loop.......Thank you
    No problems, by that point in the day, most anything could throw me.

    I suspect the problem is this line:
    [vba]
    Set rngColor = Range(Cells(1, 1), Cells(UsedRange.SpecialCells(xlCellTypeLastCell).Row, 1))
    [/vba]

    I think it probably needs to be:
        Set rngColor = SomeSheet.Range( _
                         SomeSheet.Cells(1, 1), _
                         SomeSheet.Cells(SomeSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row, 1) _
                                       )
    Where 'SomeSheet' is a sheet that is referenced.


    If this is not clear, I would suggest showing us your current loop.

    Mark

  12. #12
    VBAX Regular
    Joined
    Apr 2010
    Posts
    39
    Location
    hello, gto, the macro can work already, thank you all.

Posting Permissions

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