+ Reply to Thread
Results 1 to 8 of 8

Code to mark mandatory fields before save

  1. #1
    Registered User
    Join Date
    02-12-2013
    Location
    Essex
    MS-Off Ver
    Office Professional Plus 2010
    Posts
    21

    Code to mark mandatory fields before save

    Hi Guys, me again!

    Right im having a few troubles with some code im writing.

    What im trying to acheive, is that a macro runs on the "Workbook_BeforeSave", checking that a few cells that HAVE to be filled in, are infact filled in... now i had a piece of code that checked the cells and fired up a MsgBox, but in order to check each and every specified cell, it had to run an "If"
    on each of them, end up with me having to click ok to several different message boxes.
    this is the code that did that:
    Please Login or Register  to view this content.
    Now as stated above, i couldnt have several MsgBoxes apearing everytime, so i figured, one script, to check all cells, one at a time, in a loop or something, filling in the background red as it found a field that wasnt filled, that was meant to be, then throwing up a MsgBox at the end IF there are fields un-filled. if all fields are filled, then obviously, carry on saving...

    This is what i have been playing with, which just doesnt work at all, but should give you a flavour of what im looking for:

    Please Login or Register  to view this content.
    If anyone can help me figure this out it would be great! im just trying to "Idiot Proof" purchase orders and my work
    Last edited by ukhellfire; 02-21-2013 at 06:15 AM.

  2. #2
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628

    Re: Code to mark mandatory fields before save

    You could use this code:
    Please Login or Register  to view this content.
    Regards,
    Antonio

  3. #3
    Registered User
    Join Date
    02-12-2013
    Location
    Essex
    MS-Off Ver
    Office Professional Plus 2010
    Posts
    21

    Re: Code to mark mandatory fields before save

    Ahhh brilliant! i shall give this a go! good to see i was going along the right lines tho, just a few things i missed out...
    ill report back as soon as ive tested this

  4. #4
    Registered User
    Join Date
    02-12-2013
    Location
    Essex
    MS-Off Ver
    Office Professional Plus 2010
    Posts
    21

    Re: Code to mark mandatory fields before save

    That works perfectly! on your part anyway, i just specified the wrong cells apparently! haha! but after putting in the right cells, its perfect! thank you!
    one more question though, is there anyway, so that when you hit save again, after being told to fill in the fields and doing it, it changes the cells back to the original color? just so its tidy when it is eventually saved???

  5. #5
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628

    Re: Code to mark mandatory fields before save

    I don't think that it's possible to restore original cell color because we don't save it before to apply red color but to remove red color you could use this code:
    Please Login or Register  to view this content.
    Regards,
    Antonio

  6. #6
    Registered User
    Join Date
    02-12-2013
    Location
    Essex
    MS-Off Ver
    Office Professional Plus 2010
    Posts
    21

    Re: Code to mark mandatory fields before save

    ahhhhh right ok i see...

    if i knew the original color, could i change:
    Please Login or Register  to view this content.
    to:

    Please Login or Register  to view this content.
    this would work wouldnt it?
    Last edited by ukhellfire; 02-21-2013 at 07:27 AM.

  7. #7
    Registered User
    Join Date
    02-12-2013
    Location
    Essex
    MS-Off Ver
    Office Professional Plus 2010
    Posts
    21

    Re: Code to mark mandatory fields before save

    It works!

    Thank you soooo much Antonio! youve helped me out big time!!

    Reagrds,

    Adrian

  8. #8
    Registered User
    Join Date
    02-12-2013
    Location
    Essex
    MS-Off Ver
    Office Professional Plus 2010
    Posts
    21

    Re: Code to mark mandatory fields before save

    Solution for "Code to mark mandatory fields before save"

    Working code:
    Please Login or Register  to view this content.

+ 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