+ Reply to Thread
Results 1 to 4 of 4

VBA macro beforeSave to check for cells that are not populated based on another cell

  1. #1
    Registered User
    Join Date
    02-04-2018
    Location
    Canberra, Australia
    MS-Off Ver
    2013
    Posts
    74

    VBA macro beforeSave to check for cells that are not populated based on another cell

    I need to stop users from saving the file if in column A they select YES from a dropdown box and don’t enter anything in Column B.

    The dropdown has blank, YES and NO.

    I have the following macro that checks for blank cells in column B but how can I change it to check for a YES in column A and blank in column B.

    If NO or blank is in column A column B can be blank.

    I use

    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Dim myRange As Range
    Set myRange = worksheets(“CentralWest”).Range(“B2:B1532”)
    If Application.WorksheetFunction.CountA(myRange) <_
    MyRange.cells.Count Then
    MsgBox “Please fill in the Comments Section”
    Cancel = True
    End If
    END SUB


    Is there a way I can change the macro to check for a “YES” in column A and column B is blank.

    If Column A is blank or “NO” column B does not require to be filled in.

    Any help appreciated

    Cheers

    Dean

  2. #2
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: VBA macro beforeSave to check for cells that are not populated based on another cell

    See if you like this.

    Please Login or Register  to view this content.
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

  3. #3
    Registered User
    Join Date
    02-04-2018
    Location
    Canberra, Australia
    MS-Off Ver
    2013
    Posts
    74

    Re: VBA macro beforeSave to check for cells that are not populated based on another cell

    Thanks JLGWhiz,

    Works a treat

    Cheers

    Dean

  4. #4
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: VBA macro beforeSave to check for cells that are not populated based on another cell

    Quote Originally Posted by DeanMcK View Post
    Thanks JLGWhiz,

    Works a treat

    Cheers

    Dean
    You're welcome,
    regards, JLG

    This is just to clean up the code for other viewers.
    Please Login or Register  to view this content.
    Last edited by JLGWhiz; 02-05-2018 at 10:42 AM.

+ 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. [SOLVED] Based on two cells data validation list should be populated in third cell with unique vals
    By anchuri_chaitanya in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-13-2014, 03:21 PM
  2. Amend the layout based on which cells are populated
    By katieshields in forum Excel General
    Replies: 0
    Last Post: 03-30-2014, 11:25 PM
  3. A function to check if a cell is populated when the workbook is opened
    By JamesGoulding85 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-04-2013, 05:10 AM
  4. [SOLVED] Formula to add cells based on like values and populated cells
    By rjlchef in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-04-2013, 10:38 PM
  5. [SOLVED] Macro to find empty cells in a range and repalce with the value of a populated cell
    By Markvx in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-23-2012, 06:44 AM
  6. Check if a cell is populated, if not, skip, but do nothing.
    By Darth269 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 02-12-2012, 05:42 PM
  7. Check to see if a cell is populated
    By bbmerc in forum Excel Formulas & Functions
    Replies: 20
    Last Post: 09-06-2005, 07:05 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