+ Reply to Thread
Results 1 to 11 of 11

Help creating VB for highlighting entire row based on cell data

  1. #1
    Registered User
    Join Date
    08-25-2008
    Location
    united states
    Posts
    12

    Help creating VB for highlighting entire row based on cell data

    Hello - hoping someone can help.

    I understand that Conditional Formatting can be used to highlight an entire row based on cell criteria. However, I have tried to create one rule to work for my entire workbook, but I can only get it to work for one worksheet. So I was wondering if there was a vb script for doing this.

    What I have is a workbook with 12 worksheets (January thru December). In each worksheet there is listed the days of the week in each row. The columns headers are Date and Day.

    So you would have:
    Date Day
    1/1/16 Monday
    1/2/16 Tuesday

    I want all rows that have Saturday and Sunday, highlighted in red.

    I'm sure this is easy to do, but I just can't figure a vb script to do this.

    Any help would be appreciated.

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Help creating VB for highlighting entire row based on cell data

    Conditional formatting is the best way to do this. This code will apply the conditional formatting to all your worksheets:

    Please Login or Register  to view this content.
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Registered User
    Join Date
    08-25-2008
    Location
    united states
    Posts
    12

    Re: Help creating VB for highlighting entire row based on cell data

    That worked perfect!! Thank you so much!!

  4. #4
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Help creating VB for highlighting entire row based on cell data

    Happy to help.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

  5. #5
    Registered User
    Join Date
    08-25-2008
    Location
    united states
    Posts
    12

    Re: Help creating VB for highlighting entire row based on cell data

    Olly,

    Along the line of the code you just gave me - is there code that will allow me to color an entire row if I plug in certain dates for holidays like Christmas, New Year's Day, etc.

    Since some holidays change year-by-year (Veteran's Day, Labor Day, etc), instead of going to that day in the spreadsheet and coloring the entire row, I wondered if there was code that I could plug in the dates and the entire row would change color?

    Any help would be appreciated.

  6. #6
    Forum Contributor
    Join Date
    06-02-2015
    Location
    delhi
    MS-Off Ver
    2010
    Posts
    104

    Re: Help creating VB for highlighting entire row based on cell data

    Put your holidays in any column as you wish and name them Holidays and then Use this code to mark them with conditional formatting

    Sub foo1()
    Dim ws As Worksheet
    For Each ws In ThisWorkbook.Worksheets
    With ws.Cells.FormatConditions.Add( _
    Type:=xlExpression, _
    Formula1:="=COUNTIF(Holidays,$A1)=1")
    .Interior.Color = 12040422 'change to suit
    End With
    Next ws
    End Sub

    Regards,
    Mandeep baluja

  7. #7
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Help creating VB for highlighting entire row based on cell data

    Create a named range "HolidayList" in your workbook which contains your holiday dates. Then add another condition to the code:

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    08-25-2008
    Location
    united states
    Posts
    12

    Re: Help creating VB for highlighting entire row based on cell data

    So I'm just a bit confused with your code. I apologize. So if I want to add "12/25/2018" and "1/1/2019" to the code, where do I put it?? I have like 13 holiday dates to add. Again, I'm sorry to ask - I'm just that code savvy.

  9. #9
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Help creating VB for highlighting entire row based on cell data

    Quote Originally Posted by gcapp View Post
    So I'm just a bit confused with your code. I apologize. So if I want to add "12/25/2018" and "1/1/2019" to the code, where do I put it?? I have like 13 holiday dates to add. Again, I'm sorry to ask - I'm just that code savvy.
    Put your dates in a list in a worksheet, and make the list a named range.

  10. #10
    Registered User
    Join Date
    08-25-2008
    Location
    united states
    Posts
    12

    Re: Help creating VB for highlighting entire row based on cell data

    So in other words - in my workbook, create a worksheet called HolidayList and list all the holidays (say from A1 thru A13), then what part of this line would I change:

    Formula1:="=COUNTIF(HolidayList,$A1)>0")

    So would i change the code to:
    Formula1:="=COUNTIF(HolidayList,$A1:$A13)>0")

    Again - I apologize. I'm trying different things but it's not working right.

  11. #11
    Forum Contributor
    Join Date
    06-02-2015
    Location
    delhi
    MS-Off Ver
    2010
    Posts
    104

    Re: Help creating VB for highlighting entire row based on cell data

    Boss you don't have to create a worksheet You can Enter your holidays in any sheet for example Sheet1!A1:A13 and then define a name for it by going to Ctrl+f3
    and use that above code formula would be Formula1:="=COUNTIF(HolidayList,$A1)>0") or Formula1:="=COUNTIF(HolidayList,$A1)=1") and Run the code

+ 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. Replies: 4
    Last Post: 11-11-2015, 06:46 PM
  2. [SOLVED] Data Validation - One Cell based on nonblanks of entire row
    By MStecker in forum Excel General
    Replies: 2
    Last Post: 05-01-2015, 08:58 AM
  3. Replies: 7
    Last Post: 12-17-2013, 02:40 PM
  4. Highlighting entire row based on a single cell value
    By icerman in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-14-2012, 12:40 PM
  5. highlighting entire row based on condition
    By sania tariq in forum Excel General
    Replies: 2
    Last Post: 05-25-2012, 06:26 AM
  6. Help with creating a coordinate system and highlighting a cell in it
    By h3lla in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-23-2012, 04:19 PM
  7. Replies: 2
    Last Post: 04-14-2011, 12:34 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