+ Reply to Thread
Results 1 to 5 of 5

How to save macro when code is prevent saving if there's blank cells ?

  1. #1
    Registered User
    Join Date
    11-17-2016
    Location
    Asia
    MS-Off Ver
    2007
    Posts
    4

    Question How to save macro when code is prevent saving if there's blank cells ?

    as above ? Sort of new to VBA coding, so pardon my newb questions

    Have created an macro in "thisworkbook" that prevents user from saving the file should there be any blank files.

    How should i save this macro in order for the file to be sent then ? File will be sent to users for them to enter their data.

    TIA

  2. #2
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: How to save macro when code is prevent saving if there's blank cells ?

    Put a breakpoint in the procedure and use Debug/Set next statement to move the next line to execute to the end of the procedure.

    Use the Immediate Window to set event handling off
    Please Login or Register  to view this content.
    (Don't forget to turn on again after saving)

    Just a couple of ways...

  3. #3
    Registered User
    Join Date
    11-17-2016
    Location
    Asia
    MS-Off Ver
    2007
    Posts
    4

    Re: How to save macro when code is prevent saving if there's blank cells ?

    thank you for your reply

    was able to get the breakpoint down, but debug/next step was greyed out. here's the code.

    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Dim Zell As Range
    Dim flag As Boolean
    flag = False
    If Cells(1, 1) = "" Then flag = True
    For Each Zell In Range("J4:P233")
    If Zell = "" Then
    flag = True
    Exit For
    End If
    Next Zell


    Cancel = flag
    If flag Then MsgBox "Please fill in all the blanks"
    End Sub

  4. #4
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: How to save macro when code is prevent saving if there's blank cells ?

    I've no idea why the button would be greyed.

    Here's another way.

    Add a module (or use an existing module) to declare a public Variable
    Please Login or Register  to view this content.
    When declared, a boolean will have a default value of False.

    Then check the value in the BeforeSave event. If the default value of False then allow the empty cell check to proceed, but if true then simply exit. To allow you to save you set NOCHECK to True in the immediate window.

    The BeforeSave event was also rewritten a little. Why loop 1400 or so cells when you can check with 1 call to a native function. Also, as this is a Workbook level event, you need to specify which sheet the check applies to, otherwise the active sheet will be used.
    Please Login or Register  to view this content.
    Last edited by cytop; 11-17-2016 at 06:07 AM. Reason: Typo

  5. #5
    Registered User
    Join Date
    11-17-2016
    Location
    Asia
    MS-Off Ver
    2007
    Posts
    4

    Re: How to save macro when code is prevent saving if there's blank cells ?

    you are a lifesaver m8. thank you!

+ 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. How to prevent VBA Code from saving same outlook attachment again ?
    By avis_1989 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-11-2016, 12:31 PM
  2. [SOLVED] VBA to prevent saving of excel if cell is blank
    By anuj_sethi1043 in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 08-14-2014, 06:37 PM
  3. [SOLVED] Macro to lock all the Non Blank cells after saving the workbook.
    By adil.master in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-14-2014, 09:35 AM
  4. Replies: 6
    Last Post: 10-09-2013, 03:07 PM
  5. Need a VBA macro that prevent blank cells
    By gemiho in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-17-2013, 10:02 PM
  6. Code to prevent userform from saving duplicates based on 3 textboxes
    By Zygoid in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-28-2013, 11:04 AM
  7. [SOLVED] Error checking code that will prevent over-writing of a workbook when saving to PDF
    By mike_vr in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-02-2012, 10:11 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