Consulting

Results 1 to 4 of 4

Thread: COMBING MACROS

  1. #1

    COMBING MACROS

    Hello all I am trying to combine these two macros

    Sub CheckIfCellIsEmpty()
    Dim isMyCellEmpty As Boolean
    isMyCellEmpty = IsEmpty(Range("D48"))
     
    If isMyCellEmpty = True Then
    MsgBox "Intelligence Report Requires Completing & the Box Selected"
    End If
    End Sub
    ------------------------------------------------------------------------------------

    Option Explicit
    Sub SaveAsExample()
     
        Dim FName           As String
        Dim FPath           As String
     
        FPath = "z:\i Wing\Names"
        FName = Format$(Date, "yyyy-mm-dd") & " " & Sheets("Sheet1").Range("D12").Text
        ThisWorkbook.SaveAs Filename:=FPath & "\" & FName
     
    End Sub
     
    The macro I am using is this:
     
     
    Sub RunAll()
    Call CheckIfCellIsEmpty
    Call SaveAsExample
    End Sub

    When it runs the msg box comes up if D48 is not complete, however when I click OK it just continues to the second part of the macro ie: saveas.... Any thoughts
    Last edited by SamT; 09-13-2016 at 08:25 AM. Reason: Used # Icon to add CODE Tags

  2. #2
    Knowledge Base Approver VBAX Guru
    Joined
    Apr 2012
    Posts
    4,893
    Please, use code tags !

  3. #3

    CODE TAGS

    Quote Originally Posted by snb View Post
    Please, use code tags !

    Sorry I am not experienced in excel enough, not sure what you mean by code tags.....

  4. #4
    VBAX Wizard
    Joined
    Apr 2007
    Posts
    7,274
    Location
    1. There is a [#] icon that will put [ CODE ] and [/ CODE ] markers into your post. If you paste the macro between them it does some formatting (like below)

    2. Try making the test for Empty into a Boolean function (not sub) and testing the return value like this


    Option Explicit
    Sub RunAll()
        If Not IsCellEmpty(Range("D48")) Then
            Call SaveAsExample
        End If
     End Sub
    
    Function IsCellEmpty(R As Range) As Boolean
        If IsEmpty(R) Then
            MsgBox "Intelligence Report Requires Completing & the Box Selected"
            IsCellEmpty = True
        Else
            IsCellEmpty = False
        End If
     End Function
    
     Sub SaveAsExample()
         Dim FName As String
        Dim FPath As String
        FPath = "z:\i Wing\Names"
        FName = Format$(Date, "yyyy-mm-dd") & " " & Sheets("Sheet1").Range("D12").Text
        ThisWorkbook.SaveAs Filename:=FPath & "\" & FName
     End Sub
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •