+ Reply to Thread
Results 1 to 27 of 27

VBA Change Effective Date based on Cell value criteria.

  1. #1
    Forum Contributor
    Join Date
    07-17-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    713

    VBA Change Effective Date based on Cell value criteria.

    Hi,

    I have column with many different effective date and which may not begin with Sunday dates. Is it possible to do a macro which change the date to Sunday Date for each cell if date is not equal sunday date?

    Thanks & Regards,
    Shiva
    Last edited by shiva_reshs; 09-20-2013 at 10:08 AM.

  2. #2
    Forum Expert Debraj Roy's Avatar
    Join Date
    09-27-2012
    Location
    New Delhi,India
    MS-Off Ver
    Excel 2013
    Posts
    1,469

    Re: VBA Sunday dates

    I guess you already have prior experience with VBA.. and you can adapt below formula in VBA..

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    or please upload a sample file.. for structure of sheet..
    Regards!
    =DEC2HEX(3563)

    If you like someone's answer, click the star to give them a reputation point for that answer...

  3. #3
    Forum Contributor
    Join Date
    07-17-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    713

    Re: VBA Sunday dates

    Hi,

    Sorry. Having issue with uploading document.

    1) Column I is the Start date which I want to be a Sunday Date. Based on a below condition.

    a) If, Column Q cell value is BW and Column I date is >= 06/30/13, else highlight the row to Yellow color.
    b) If, Column Q cell value is BS and Column I date is >= 06/16/13, else highlight the row to Yellow color.
    C) If, Column Q cell value is BA and Column I date is >= 06/09/13, else highlight the row to Yellow color.
    d) If, Column Q cell value is BZ and Column I date is >= 07/01/13, else highlight the row to Yellow color.


    Thanks
    Shiva
    Attached Files Attached Files
    Last edited by shiva_reshs; 09-19-2013 at 12:36 PM.
    Keep the Forum clean :


    1. Use [ code ] code tags [ /code ]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    2. Show appreciation to those who have helped you by clicking * Add Reputation below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

  4. #4
    Forum Contributor
    Join Date
    07-17-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    713

    Re: VBA Change Effective Date based on Cell value criteria.

    90 views so far.

    Is this code possible or too much coding required?

    Thanks..

  5. #5
    Forum Contributor
    Join Date
    07-17-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    713

    Re: VBA Change Effective Date based on Cell value criteria.

    After 2 days of trial n error, I was able to make up a code which changes the dates to a sunday date.

    Please Login or Register  to view this content.
    but, I am not able to get the coloring right for cell. The problem I am facing are

    1) Some cell getting colored to yellow, even though the dates are Sunday Date.
    2) When I second time run this macro, every cell is getting colored to Yellow.


    Appreciate, if someone have any tips on it.

    Thanks

  6. #6
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: VBA Change Effective Date based on Cell value criteria.

    It looks like on your workbook column Q is empty, therefore all the cells are getting set to yellow. I'd probably do something like:

  7. #7
    Forum Contributor
    Join Date
    07-17-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    713

    Re: VBA Change Effective Date based on Cell value criteria.

    I believe your reply was not saved.

    like??? what???

  8. #8
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: VBA Change Effective Date based on Cell value criteria.

    Sorry, I meant to delete it as decided it wasn't relevant. Meant to delete the last bit of the reply.

  9. #9
    Forum Contributor
    Join Date
    07-17-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    713

    Re: VBA Change Effective Date based on Cell value criteria.

    ohhk.

    I updated entire column Q till data but still same issue.

  10. #10
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: VBA Change Effective Date based on Cell value criteria.

    Please upload new workbook with data.

  11. #11
    Forum Contributor
    Join Date
    07-17-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    713
    Here is the file

    Thanks

    Sorry. I just missed to update the workrage to
    Please Login or Register  to view this content.
    from old

    Please Login or Register  to view this content.
    File is same just incase you get debug error messages.

    Thanks
    Attached Files Attached Files
    Last edited by shiva_reshs; 09-24-2013 at 10:34 AM.

  12. #12
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: VBA Change Effective Date based on Cell value criteria.

    Please Login or Register  to view this content.
    ?

  13. #13
    Forum Contributor
    Join Date
    07-17-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    713

    Re: VBA Change Effective Date based on Cell value criteria.

    woo.. Thats was very fast...

    Cool.....

    One more query though. I was able to code it as per single condition. But if you look my original post, I have been trying to do it for 4 different condition.

    a) If, Column Q cell value is BW and Column I date is >= 06/30/13, else highlight the row to Yellow color.
    b) If, Column Q cell value is BS and Column I date is >= 06/16/13, else highlight the row to Yellow color.
    C) If, Column Q cell value is BA and Column I date is >= 06/09/13, else highlight the row to Yellow color.
    d) If, Column Q cell value is BZ and Column I date is >= 07/01/13, else highlight the row to Yellow color.

    Can these be coded on a single macro above?? or Should I need to create 4 different macros??

    Thanks

  14. #14
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: VBA Change Effective Date based on Cell value criteria.

    Maybe:
    Please Login or Register  to view this content.

  15. #15
    Forum Contributor
    Join Date
    07-17-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    713

    Re: VBA Change Effective Date based on Cell value criteria.

    I get this error message

    Please Login or Register  to view this content.

  16. #16
    Forum Contributor
    Join Date
    07-17-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    713

    Re: VBA Change Effective Date based on Cell value criteria.

    Removed the spaces

    Please Login or Register  to view this content.
    it work now..

  17. #17
    Forum Contributor
    Join Date
    07-17-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    713

    Re: VBA Change Effective Date based on Cell value criteria.

    just for my learning. These days, I am playing around with offset function.

    So in your above code, when Column I changes to Sunday date; how can I add the offset , so the next cell (Column J) changes to Next Saturday date??

    Or should I rebuild the code for Column J, Instead of using offset function here?

    Thanks

  18. #18
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: VBA Change Effective Date based on Cell value criteria.

    Please Login or Register  to view this content.

  19. #19
    Forum Contributor
    Join Date
    07-17-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    713

    Re: VBA Change Effective Date based on Cell value criteria.

    Not sure what went wrong, I added offset like below.

    Please Login or Register  to view this content.
    Result is

    PHP Code: 
    Start Date*    End Date
          2013
    -04-04    2013-08-17
          2013
    -06-15    2013-08-17
          2013
    -04-07    2013-08-17
               FALSE    2013
    -08-15
          2013
    -06-30    2013-08-17
               FALSE    2013
    -08-17
               FALSE    2013
    -08-17 
    I added offset code only at BW cell. So I got error only with cell value of BW.
    Last edited by shiva_reshs; 09-24-2013 at 11:10 AM.

  20. #20
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: VBA Change Effective Date based on Cell value criteria.

    You can't have your code on one line like that, you need:
    Please Login or Register  to view this content.
    I added some extra .values in case that helped.

  21. #21
    Forum Contributor
    Join Date
    07-17-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    713

    Re: VBA Change Effective Date based on Cell value criteria.

    Thanks it works..

    What it is doing now is, if there is Date 08/15/2013, it goes back to previous Saturday to 08/10/2013. But If I want to make it coming days Saturday, i.e 08/17/2013?? then how?

    Note: Sunday function perfect. I am just curious to understand, how to make it cell changes to Next saturday on next column cell..

    Thanks.

  22. #22
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: VBA Change Effective Date based on Cell value criteria.

    Can you upload your code again, as far as I can see it gives the next saturday

  23. #23
    Forum Contributor
    Join Date
    07-17-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    713
    Here it is..

    Thanks
    Attached Files Attached Files

  24. #24
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: VBA Change Effective Date based on Cell value criteria.

    works fine?

  25. #25
    Forum Contributor
    Join Date
    07-17-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    713

    Re: VBA Change Effective Date based on Cell value criteria.

    In Column J9, effective date I had entered is 08/15/2013. VBA turns the date to saturday date, but of previous week i.e 08/10/2013.
    I am trying change the date to coming Saturday date , i.e 08/17/2013.

    I hope, I am not confusing you again..

    Thanks

  26. #26
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: VBA Change Effective Date based on Cell value criteria.

    You asked for:
    So in your above code, when Column I changes to Sunday date; how can I add the offset , so the next cell (Column J) changes to Next Saturday date??

    So in I9 you have 04/08/2013 therefore J9 should changed to 10/08/2013.

    If you want to just change it to the next saturday after the date you entered in the cell just do it in a separate macro the same way you did the sundays, no need to use offset functions.

  27. #27
    Forum Contributor
    Join Date
    07-17-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    713

    Re: VBA Change Effective Date based on Cell value criteria.

    ohhk..

    Thanks yudlugar!!

    Regards,

+ 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. VBA Sunday dates
    By shiva_reshs in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-11-2013, 03:38 PM
  2. Find how many date between two dates but excluding Sunday and holiday
    By tantcu in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-05-2013, 05:06 PM
  3. Difference between two dates and time excluding Sunday
    By arafats in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 06-28-2013, 02:44 AM
  4. IF Statments pertaining to dates and if it lands on a Saturday or Sunday
    By RanS2011 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 04-22-2013, 11:30 AM
  5. Column of Sunday Dates
    By BigJohnW in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-20-2013, 05:52 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