+ Reply to Thread
Results 1 to 12 of 12

Worksheet Activate Macro for highlighting rows based on the date which is end of month

  1. #1
    Forum Contributor
    Join Date
    12-26-2015
    Location
    UAE
    MS-Off Ver
    2013
    Posts
    128

    Worksheet Activate Macro for highlighting rows based on the date which is end of month

    Hello All,

    I have excel 2013

    There are 2 sheets

    Sheet1, Sheet2

    Data Starts from Row 12 on Sheet1 and Sheet2 (as shown in the sample attached)

    I want a Worksheet_Activate Macro

    Which should look up for dates in Col D and highlight the entire row based on the dates of the end of the month

    If multiple entries are there for the end of the month then only the last row should be highlighted
    Eg Sheet1- Row 19 and Row 20 are both 31-Jan-2018 then only Row 20 to be highlighted.

    If the end of the Month is Friday or Saturday then it should highlight the day which is a day before
    Eg Sheet2- Row 28 is 29-Mar-2018 which is a Thursday and it is highlighted and Row 35 is 28-Jun-2018 which is highlighted. Also Row 42 is 30-Aug-2018 which is a Thursday and it is highlighted

    If the end of the month date is falling on a Friday or Saturday, the previous Thursday row to be highlighted

    Hope I am clear

    Any help would be appreciated
    Thanks in advance
    Rehana
    Last edited by rehana402003; 09-03-2018 at 07:08 AM.

  2. #2
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Worksheet Activate Macro for highlighting rows based on the date which is end of month

    If the end of the month date is falling on a Friday or Saturday, the previous Thursday row to be highlighted
    If exists a record for 29 March 2018 (Thursday ) and another one for 31 March 2018 ( Saturday) we need to highlight Thursday record then the Saturday is not highlighted then
    the entire row based on the dates of the end of the month is not highlighted
    IS it OK ??
    - Battle without fear gives no glory - Just try

  3. #3
    Forum Contributor
    Join Date
    12-26-2015
    Location
    UAE
    MS-Off Ver
    2013
    Posts
    128

    Re: Worksheet Activate Macro for highlighting rows based on the date which is end of month

    Hello PCI
    Yes there will be no highlights for any days if the end of the month is Fridays or Saturdays (as these are none working days for us)
    The entire row till Col N should be highligted
    I missed one cell. Sorry for that

    Thanks for your time

  4. #4
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Worksheet Activate Macro for highlighting rows based on the date which is end of month

    Yes there will be no highlights for any days if the end of the month is Fridays or Saturdays (as these are none working days for us)
    The entire row till Col N should be highligted
    or do you mean

    The entire row till Col N should NOT be highligted

  5. #5
    Forum Contributor
    Join Date
    12-26-2015
    Location
    UAE
    MS-Off Ver
    2013
    Posts
    128

    Re: Worksheet Activate Macro for highlighting rows based on the date which is end of month

    Dear PCI,
    Sorry for the confusion
    Following is my requirement
    I will be doing entries everyday in both Sheet1 and Sheet2
    which has already some conditional formatting applied for various conditions

    When the entry is done for the last day of the month and the file opened the next time the row with the last date of the month should be highlighted. Friday and Saturday are non working days.
    I want the row till column N to be highlighted indicating the entry of the last day of that particular month.

    There may be more than one entry for the same date which will be the last day of the month.
    I want the last entry to be highlighted. eg Sheet1 see Row 19 and 20. Row 20 is highlighted. same in Sheet2

    If the last day of the month is a Friday or a Saturday (eg Mar 2018 and Aug 2018) then the row of previous day should be highlighted

    I am enclosing another attachment for explanation purpuse
    I have colored all the cells upto Col N manually

    Hope the requirement is clear now

    Thanks for your time once again.

  6. #6
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2016
    Posts
    5,913

    Re: Worksheet Activate Macro for highlighting rows based on the date which is end of month

    Try this formula for Conditional Formatting:

    =MONTH($D13)<>MONTH($D14)

  7. #7
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Worksheet Activate Macro for highlighting rows based on the date which is end of month

    In VBA in ThisWorbook folder put next code
    See file attached to
    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    12-26-2015
    Location
    UAE
    MS-Off Ver
    2013
    Posts
    128

    Re: Worksheet Activate Macro for highlighting rows based on the date which is end of month

    Dear PCI
    I have done some testing on the file attached herewith and noticed a strange behavior which I would like to share with you.
    Workbook_Activate Macro does only one sheet with the correct output
    The second sheet does not give the correct output
    It can be Sheet1 or Sheet2 but not both the sheet shows the correct results

    I have cleared the fill colors, saved and reopened the workbook and tested it several times

    I noticed one thing that while opening the workbook if Sheet1 is active then the result would be correct on Sheet1 and if Sheet2 is active then it would give the correct result on Sheet2
    However the module works perfect if run on each sheet individually.
    I wanted to share my test with you.

    Any thoughts?

    Thanks for your time once again.

  9. #9
    Forum Contributor
    Join Date
    12-26-2015
    Location
    UAE
    MS-Off Ver
    2013
    Posts
    128

    Re: Worksheet Activate Macro for highlighting rows based on the date which is end of month

    Hello Phuocam
    Thanks for your solution too.

    Regards

  10. #10
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Worksheet Activate Macro for highlighting rows based on the date which is end of month

    Yes there was a mistake, but it shown also a limit not specified: Clear filter to avoid missing rows
    See next code
    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    12-26-2015
    Location
    UAE
    MS-Off Ver
    2013
    Posts
    128

    Re: Worksheet Activate Macro for highlighting rows based on the date which is end of month

    Thanks PCI
    Reputation added
    Post marked SOLVED

  12. #12
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Worksheet Activate Macro for highlighting rows based on the date which is end of month

    Good news
    Have a great day

+ 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. Macro to copy rows and populate month/year based on start date?
    By ekwacillin in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-26-2016, 03:35 PM
  2. Macro to hide rows based on selected Month
    By toci in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 03-14-2016, 04:33 PM
  3. [SOLVED] Highlighting multiple rows through a worksheet depending a cell value in the rows
    By loked in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-19-2014, 01:31 AM
  4. [SOLVED] How Do I Write a Macro for Highlighting Rows Based on Date Criteria
    By TMack in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-21-2013, 11:15 AM
  5. Conditional Formula - highlighting month column based on todays date
    By frogboy in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-09-2012, 10:49 AM
  6. Macro to pick a date, find month and transpose into another worksheet
    By apbbsr in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-27-2012, 12:40 PM
  7. Macro for Highlighting Rows based on Cell Value
    By ExcelNoobNJ in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-29-2008, 08:08 AM

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