Skip to Content
author's profile photo Former Member
Former Member

VBA Macros code to run a validation using BEFORE_SAVE Function and to Save Data

Hi Experts,

I am struggling to come out with the correct syntax to combine the "Before_Save ()" function and "SaveAndRefreshWorkbookData() ".

I have some cells running validations and i want the Macros to evaluate this cells and based on their value execute the "SaveAndRefreshWorkbookData() " or display a message box asking to "Check Calculation"...anyone with some ideas willing to share the syntax?


Thanks.

Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Best Answer
    Posted on Apr 25, 2016 at 08:50 PM

    Maleo,

    what sort of validation are you trying to run? Can you provide an example?

    Akos

    Add a comment
    10|10000 characters needed characters exceeded

    • Yes, you can use Excel function to aggregate the check result!

      The same can be done in VBA:

      Dim cell As Range

      BEFORE_SAVE = True

      For Each cell In Range("C4:C13").Cells

      If cell.Value = "MISMATCHES" Then

      BEFORE_SAVE = False

      Exit For

      End If

      Next cell

      P.S. Or faster code:

      Dim varCheck() As Variant

      Dim lngTemp As Long

      varCheck = Range("C4:C13").Value

      BEFORE_SAVE = True

      For lngTemp = 1 To UBound(varCheck, 1)

      If varCheck(lngTemp, 1) = "MISMATCHES" Then

      BEFORE_SAVE = False

      Exit For

      End If

      Next lngTemp

  • Posted on Apr 25, 2016 at 08:39 PM

    But what is the issue?

    BEFORE_SAVE will be triggered if SAVE is launched

    Inside this function you can perform validation and in case of error set BEFORE_SAVE=False.

    You don't need to execute SaveAndRefreshWorkbookData

    Vadim

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.