+ Reply to Thread
Results 1 to 6 of 6

VBA Pseudo Conditional Formatting With User Log In

  1. #1
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    VBA Pseudo Conditional Formatting With User Log In

    A while ago a User asked a question with somewhat complicated conditional formatting that also required an existing User Id. I can't find the original question, but I was interested in the question, and had some time for a solution. The question was something like:

    I am looking to conditionally format column B. In column C, there is a ‘Date to be completed’.

    If there is no date in column C, column B should not be formatted.
    If column C has a date, and today’s date is within 7 days plus or minus, column B cell should be yellow.
    If today’s date greater than 7 days from the column C date, column B cell should be red.
    Once a date is entered in column E – completed date field – I would like whatever condition that may have been applied above to persist.

    In column E, I have a completed date field. Once the completed date is entered, column A cell should be green.

    In column H, ‘Completed By’ column – is there any way to auto populate the user that inputs the completed date in column E? No idea if that is a possibility.

    -------------------
    I translated the above requirements into the following that was easier for me to follow:
    a. Add 'Completed By' Name in Column 'H' when date is entered in Column 'E'.

    b. Turn Column 'A' green when Column 'E' has a date.


    c. Column 'B' no Color when, Column 'C' is BLANK.
    d. Column 'B' Yellow when, Column 'C' is <= Today +/- 7 days.
    e. Column 'B' red when, Column 'C' is > Today +/- 7 days.
    f. Column 'B' DOES NOT CHANGE COLOR when there is a Date in Column 'E'

    -----------------
    Since I am not very good at Conditional formatting (maybe that is why I don't like it), I solved the problem (see attached file and code below) using:
    a. Small UserForm to select from a list of pre-existing User Ids.
    b. Worksheet_Change event handlers to satisfy the other requirements

    In the ThisWorkbook Code module:
    Please Login or Register  to view this content.
    In the Sheet1 Code module:
    Please Login or Register  to view this content.
    In the UserFormLogin Code Module:
    Please Login or Register  to view this content.
    In the ModPseudoConditionalFormattingOrdinary Code module:
    Please Login or Register  to view this content.
    In the ModUserFormLoginOrdinary Code module:
    Please Login or Register  to view this content.
    Lewis

  2. #2
    Registered User
    Join Date
    01-25-2015
    Location
    Minneapolis, MN
    MS-Off Ver
    Windows 7
    Posts
    36

    Re: VBA Pseudo Conditional Formatting With User Log In

    That is pretty awesome, Lewis. Thank you.

    I was trying to make 1 tweak.....regarding: If today’s date is greater than 7 days from the column C date, column B cell should be red.

    The cell should only go red if I am 8 days or more 'past due'. So if column C had a 'date to be completed' date of 1/13, come tomorrow, that would go from yellow to red. The ABS +/- for the yellow condition is perfect...for red, it should be +8 or more - red - and currently it is doing +8 and -8 red.

    Didn't have success making the tweak! The user login form is pretty cool - so the only maintenance there is add the users to the code, and re-alphabetizing as new users were added if that was my preference. Thank you again - really appreciate it.

  3. #3
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: VBA Pseudo Conditional Formatting With User Log In

    Hi Ryan,

    Thanks for the rep points. Try the attached file, changes I made are in red below:
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    01-25-2015
    Location
    Minneapolis, MN
    MS-Off Ver
    Windows 7
    Posts
    36

    Re: VBA Pseudo Conditional Formatting With User Log In

    Worked perfectly. Thank you again Lewis. Greatly appreciated.

  5. #5
    Registered User
    Join Date
    01-25-2015
    Location
    Minneapolis, MN
    MS-Off Ver
    Windows 7
    Posts
    36

    Re: VBA Pseudo Conditional Formatting With User Log In

    Hi Lewis, follow-up question for you.

    This section of code you have in the 'ThisWorkbook' module:

    'Verify the Pseudo Conditional Formatting on the Data Sheet
    Application.EnableEvents = False
    Call PseudoConditionalFormattingInDataEntryRange(Worksheets(sGblDataEntrySheetNAME).Range(sGblDataEntryRANGE))
    Application.EnableEvents = True


    I am working on some other macros - and in testing something - I did remove the entry above and all of your conditional formatting appears to function as designed. Since the functionality appears to still work, curious as to what the code above in that specific module is doing. Thanks!

  6. #6
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: VBA Pseudo Conditional Formatting With User Log In

    It is a defensive programming technique.

    If for some reason, either intentionally (or due to error) events are disabled, my code will not operate because it relies on Excel events to be enabled. The Workbook_Open() event in the ThisWorkbook module (that contains the above code) is automatically run when the workbook is opened and Excel Events are enabled. This will take a little time, but will guarantee that the contents of your sheet are correct. In a perfect world, the code is not necessary.

    I turn events off and on while the code is running, because the code modifies cell values (and could possibly call itself over and over again forever). Sort of like a dog chasing it's tail.

    Lewis

+ 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 for conditional formatting based on user selected color
    By phrankndonna in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-29-2017, 09:55 AM
  2. [SOLVED] Conditional formatting changes based on user selection
    By jrholden in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-17-2013, 05:07 PM
  3. Conditional formatting changes based on user selection
    By jrholden in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-17-2013, 01:09 PM
  4. Macro will not allow conditional formatting with a user-defined function
    By Med_MV in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-16-2013, 05:28 PM
  5. conditional formatting if the user has edited the cell?
    By bauerbach in forum Excel General
    Replies: 2
    Last Post: 06-21-2012, 10:15 AM
  6. [SOLVED] Script which allows user to define the color in conditional formatting
    By PariD in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-13-2012, 03:55 PM
  7. Replies: 3
    Last Post: 08-17-2007, 06:52 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