-
COMBING MACROS
Hello all I am trying to combine these two macros
Code:
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
------------------------------------------------------------------------------------
Code:
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
-
-
CODE TAGS
Quote:
Originally Posted by
snb
Please, use code tags !
Sorry I am not experienced in excel enough, not sure what you mean by code tags.....
-
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
Code:
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