+ Reply to Thread
Results 1 to 27 of 27

Highlight Dynamic Rows

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-16-2010
    Location
    Australia
    MS-Off Ver
    Excel 2007; Excel 2010
    Posts
    178

    Highlight Dynamic Rows

    Hi All,

    I have an issue where I need to highlight all columns which have a SAT or SUN as date.

    I can do that ok, but if I insert a new row for another product everything is out of whack due to hard coding.

    But I don;t know where to start to address this issue.

    Can anybody steer me in the correct direction.

    I have attached a workbook as to what I have done so far.

    Thanks

    Lionel
    Last edited by Foreverlearning; 03-10-2012 at 06:49 PM.

  2. #2
    Forum Contributor johnjohns's Avatar
    Join Date
    11-19-2007
    Location
    Dubai, UAE
    MS-Off Ver
    2003 and 2007
    Posts
    526

    Re: Highlight Dynamic Rows

    Perhaps this way. I have used Text function to arrive the day and used conditional formatting to highlight the holidays. See the attachment.
    Attached Files Attached Files
    regards

    johnjohns

    When you are not sure where to go, every road takes you there!

  3. #3
    Forum Contributor
    Join Date
    06-16-2010
    Location
    Australia
    MS-Off Ver
    Excel 2007; Excel 2010
    Posts
    178

    Re: Highlight Dynamic Rows

    Hi johnjohns,

    Sorry no go as it hi-lights the whole column.
    In my example I had sections where the highlight did not extend too.
    I need the date section as date as it is read by another code source as well.

    I prefer a VBA solution

    Thanks
    Lionel

  4. #4
    Forum Contributor johnjohns's Avatar
    Join Date
    11-19-2007
    Location
    Dubai, UAE
    MS-Off Ver
    2003 and 2007
    Posts
    526

    Re: Highlight Dynamic Rows

    You can select ranges and clear the conditional formatting from there. I would suggest to use excel's built in features if that helps. See the attachment. I have removed the text function also
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    06-16-2010
    Location
    Australia
    MS-Off Ver
    Excel 2007; Excel 2010
    Posts
    178

    Re: Highlight Dynamic Rows

    Sorry, but there is a larger issue to this as there are other factors involved here.

    Yes, inbuilt would be best, but when you are setting up for other users and the sheet gets used as a template amongst other issues
    it is not an option.

    Lionel

  6. #6
    Forum Contributor johnjohns's Avatar
    Join Date
    11-19-2007
    Location
    Dubai, UAE
    MS-Off Ver
    2003 and 2007
    Posts
    526

    Re: Highlight Dynamic Rows

    Select the area under dates (exluding the rows you want to spare) and run the below macro

    Sub ToHighlight()
      Dim OneCell As Range
      For Each OneCell In Selection.Cells
         If IsDate(Cells(5, OneCell.Column)) Then
            If Format(Cells(5, OneCell.Column), "ddd") = "Sat" Or Format(Cells(5, OneCell.Column), "ddd") = "Sun" Then
               OneCell.Interior.ColorIndex = 20
            Else
               OneCell.Interior.ColorIndex = xlNone
            End If
         End If
      Next OneCell
    End Sub
    if your date is not in 5th row then chnage the below
    Cells(5,
    to your requirement

  7. #7
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Highlight Dynamic Rows

    Sub snb()
     For Each ar In Sheets("Work 1").Columns(8).SpecialCells(2).Areas
      For j = 0 To Sheets("Work 1").Cells(5, Columns.Count).End(xlToLeft).Column Step 7
       ar.Offset(, j + (7 - Weekday(Sheets("Work 1").Cells(5, 10), 2)) + 1).Resize(, 2).Interior.ColorIndex = 14
      Next
     Next
    End Sub
    or

    Sub snb_001()
     With Sheets("Work 1")
       For j = 0 To .Cells(5, Columns.Count).End(xlToLeft).Column Step 7
         With .Columns(8).SpecialCells(2).Offset(, j + (7 - Weekday(.Cells(5, 10), 2)) + 1)
           .Interior.ColorIndex = 12
           .Offset(, 1).Interior.ColorIndex = 12
         End With
       Next
     End With
    end sub
    Last edited by snb; 03-05-2012 at 09:17 AM.



  8. #8
    Forum Contributor johnjohns's Avatar
    Join Date
    11-19-2007
    Location
    Dubai, UAE
    MS-Off Ver
    2003 and 2007
    Posts
    526

    Re: Highlight Dynamic Rows

    That was a typical snb approach . Fewer codes and better solution! Adding to my learning

  9. #9
    Forum Contributor
    Join Date
    06-16-2010
    Location
    Australia
    MS-Off Ver
    Excel 2007; Excel 2010
    Posts
    178

    Re: Highlight Dynamic Rows

    Hi Fellas,

    Tried all three but, Oh! not really doing the job.

    Can I explain some more details.

    There will be rows inserted every now and then on a template when needed and the template is copied as a active sheet when required.
    A date will be entered at a fixed point but date range across columns are dynamic.

    The number of rows from the date cell varies (but same number for each column) a product number is a reference point on the left.

    I am trying to via VBA check by (column) date header(Date always in row 5) and if SAT or SUN and check each (ROW) if a product number highlight that cell.

    I have done repetitively for a fixed number of rows (messy though) but need dynamic based on product number which will have gaps in between.

    Thank You

    Lionel

  10. #10
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Highlight Dynamic Rows

    Tried all three but, Oh! not really doing the job.
    The code is doing the job you presented.

    Proper designing precedes coding.

  11. #11
    Forum Contributor
    Join Date
    06-16-2010
    Location
    Australia
    MS-Off Ver
    Excel 2007; Excel 2010
    Posts
    178

    Re: Highlight Dynamic Rows

    Ok, the codes did the job to your understanding, but my bad if it is not understood to my last post.

    Can you steer me in the right direction

    Thanks

    Lionel

  12. #12
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Highlight Dynamic Rows

    Hi Lionel
    I'm not certain I understand the issue but, based on my understanding, try this:
    In Sheet1 Module place this code
    Private Sub Worksheet_Change(ByVal Target As Range)
       If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
        If Target.Address = "$J$5" Then
            Call cmdSAT_SUN_Click
        End If
    End Sub
    Replace your cmdSAT_SUN_Click code with this
    Option Explicit
    Sub cmdSAT_SUN_Click()
        Dim wsActive As Worksheet, rngDay As Range, c As Range
        Dim LastCol As Integer, strDate As String
        Dim LR As Long
        If ActiveSheet.Name = "TEMPLATE" Then Exit Sub
        Set wsActive = ActiveSheet
        With wsActive
            LastCol = .Cells(5, .Columns.Count).End(xlToLeft).Column    'Row 5
            LR = .Cells.Find("*", .Cells(Rows.Count, .Columns.Count), SearchOrder:=xlByRows, _
                    SearchDirection:=xlPrevious).Row
            .Range(.Cells(5, 10), Cells(LR, LastCol)).Interior.TintAndShade = 0
        End With
        With wsActive
            .AutoFilterMode = False
            .Range("D4:D" & LR).AutoFilter Field:=1, Operator:= _
                    xlFilterNoFill
        End With
        Set rngDay = wsActive.Range("J5:" & Cells(5, LastCol).Address)
        For Each c In rngDay
            strDate = Format(c, "ddd")
            Select Case strDate
            Case Is = "Sat", "Sun"
                Range(Cells(6, c.Column), Cells(LR, c.Column)).SpecialCells(xlCellTypeVisible).Interior.Color = &HFFFFC0
            End Select
        Next c
        wsActive.AutoFilterMode = False
    End Sub
    See attached...let me know of issues.
    Attached Files Attached Files
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  13. #13
    Forum Contributor
    Join Date
    06-16-2010
    Location
    Australia
    MS-Off Ver
    Excel 2007; Excel 2010
    Posts
    178

    Re: Highlight Dynamic Rows

    Hi jaslake,

    Glad you called in. Thank you for your interest.

    Basically you are on the right track, but as you see in worksheet there are rows which are grey or white in between the coloured cells.
    These are the cells I did't want to be coloured. They contain specific info which I wanted to be white.

    I hope I haven't confused everybody. But I will explain more if needed.

    Thanks mate.

    Lionel

  14. #14
    Forum Contributor
    Join Date
    06-16-2010
    Location
    Australia
    MS-Off Ver
    Excel 2007; Excel 2010
    Posts
    178

    Re: Highlight Dynamic Rows

    Hi jaslake,

    After re-examining your code and found it was doing what is suppose to, but based on Auto filter (not quite sure what on though)

    I thought I would upload a more exact version of my current file minus a lot of stuff so you can see what I am trying to explain.

    Thank you for your time and interest'

    Lionel

  15. #15
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Highlight Dynamic Rows

    Hi Lionel
    Please post a workbook that includes this
    Below that is various data reports
    I need to see what these rows are and if they follow your shading scheme. The code I posted depends on finding the last row that needs shading applied.

    One other thing
    there are rows which are grey or white in between the coloured cells
    I'm terribly color blind. I DO see the gray colored cells. If by white you mean NO COLOR then we're fine if you truly mean shaded white then I'm out of business...I don't see them.

  16. #16
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Highlight Dynamic Rows

    Hi Lionel
    I think I've got the Color thing figured out...it appears all cells are filled with white...unless they're not. Let me see your file with the various data reports below.

  17. #17
    Forum Contributor
    Join Date
    06-16-2010
    Location
    Australia
    MS-Off Ver
    Excel 2007; Excel 2010
    Posts
    178

    Re: Highlight Dynamic Rows

    Thank you jaslake again for your continued interest in helping me.
    Much appreciated..

    I have added as requested.

    Lionel
    Attached Files Attached Files

  18. #18
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Highlight Dynamic Rows

    Hi Lionel
    In your sample file Cell A275 says "Header 7". I need to find that row so, what does it say in the real world and does it ALWAYS say that?

  19. #19
    Forum Contributor
    Join Date
    06-16-2010
    Location
    Australia
    MS-Off Ver
    Excel 2007; Excel 2010
    Posts
    178

    Re: Highlight Dynamic Rows

    Also to mention,
    While the Header will always say MEASUREMENTS the cell address may not always be the same
    But always Column A though.

    Thanks
    Lionel
    Last edited by Foreverlearning; 03-09-2012 at 01:28 AM. Reason: Additional info

  20. #20
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Highlight Dynamic Rows

    Hi Lionel

    This code is in the attached:
    In 12-Mar Worksheet Module
    Option Explicit
    Private Sub Worksheet_Change(ByVal Target As Range)
        If Not Intersect(Target, Me.Range("D3")) Is Nothing Then
            Call cmdSAT_SUN_Click
        End If
    End Sub
    In a General Module
    Option Explicit
    Sub cmdSAT_SUN_Click()
        Dim wsActive As Worksheet
        Dim rngDay As Range
        Dim c As Range
        Dim LC As Long
        Dim strDate As String
        Dim LR As Long
        Dim myCol As Long
        Dim cel As Range
    
        If ActiveSheet.Name = "TEMPLATE" Then Exit Sub
        Set wsActive = ActiveSheet
        Application.ScreenUpdating = False
        With wsActive
            LC = .Cells(5, .Columns.Count).End(xlToLeft).Column    'Row 5
            LR = .Cells.Find("*", .Cells(Rows.Count, .Columns.Count), SearchOrder:=xlByRows, _
                    SearchDirection:=xlPrevious).Row
    
            ' Sat & Sun Columns have moved so, find the first Column in Row 6 with a Blue Cell
            For Each cel In .Range(.Cells(6, 10), (.Cells(6, LC)))
                If cel.Interior.Color = &HFFFFC0 Then
                    myCol = cel.Column
                    Exit For
                End If
            Next cel
    
            ' Filter on Blue Cells
            On Error Resume Next    'In case there are no Blue Cells
            .Range(.Cells(4, myCol), (.Cells(LR, myCol))).AutoFilter Field:=1, Criteria1:=&HFFFFC0, _
                    Operator:=xlFilterCellColor
    
            ' Make them all White
            .Range(.Cells(4, 10), (.Cells(LR, LC))).Offset(1, 0).SpecialCells(xlCellTypeVisible).Interior.Color = vbWhite
            .AutoFilterMode = False
            On Error GoTo 0
    
            ' Now filter on the White Cells
            .Range(.Cells(4, 10), (.Cells(LR, LC))).AutoFilter Field:=1, Criteria1:=RGB(255, _
                    255, 255), Operator:=xlFilterCellColor
        End With
    
        ' Find the Sat and Sun Cells and make them Blue
        Set rngDay = wsActive.Range("J5:" & Cells(5, LC).Address)
        For Each c In rngDay
            strDate = Format(c, "ddd")
            Select Case strDate
            Case Is = "Sat", "Sun"
                Range(Cells(6, c.Column), Cells(LR, c.Column)).SpecialCells(xlCellTypeVisible).Interior.Color = &HFFFFC0
            End Select
        Next c
        wsActive.AutoFilterMode = False
        Application.ScreenUpdating = True
    End Sub
    Let me know of issues.
    Attached Files Attached Files

  21. #21
    Forum Contributor
    Join Date
    06-16-2010
    Location
    Australia
    MS-Off Ver
    Excel 2007; Excel 2010
    Posts
    178

    Re: Highlight Dynamic Rows

    Hi jaslake,

    The real world header 7 is MEASUREMENTS and it is static.

    Lionel

  22. #22
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Highlight Dynamic Rows

    Why is your alias foreverlearning ?

  23. #23
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Highlight Dynamic Rows

    @snb
    BIG Smile...

  24. #24
    Forum Contributor
    Join Date
    06-16-2010
    Location
    Australia
    MS-Off Ver
    Excel 2007; Excel 2010
    Posts
    178

    Re: Highlight Dynamic Rows

    Hi jaslake,

    What can I say

    You are a legend mate.

    I will give it a whirl on my actual workbook later and post back.

    @snb
    at least I admit I am foreverlearning as you can never always know everything

    Thanks
    Lionel

  25. #25
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Highlight Dynamic Rows

    Hi Lionel
    Not a "legend"...simply looked for a connection. For your benefit, ALWAYS post a workbook that truly represents your ACTUAL file, down to the last format detail. Makes things easier to find connections and saves rewrites.

    snb is quite brilliant...well beyond my expertise and understanding...I got a rather large smile from his question...I too, with the Grace of God, am "Forever Learning".

  26. #26
    Forum Contributor
    Join Date
    06-16-2010
    Location
    Australia
    MS-Off Ver
    Excel 2007; Excel 2010
    Posts
    178

    Thumbs up Re: Highlight Dynamic Rows

    Hi jaslake,

    Thanks for the tips.

    Thank you for persisting and finding a solution.

    I tried the code on my actual workbook and ran fine, except one hiccup.

    If I leave the template blank / uncoloured date cells, the whole column gets coloured to bottom used row when I copy the template and run code.
    But if I set up the SAT-SUN columns 1st all is good.

    Dissecting your code explained why...

    Regards
    Lionel

  27. #27
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Highlight Dynamic Rows

    Hi Lionel
    You're welcome...glad I could help.

+ Reply to Thread

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