PDA

View Full Version : COMBING MACROS



Chris2460
09-13-2016, 02:32 AM
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

snb
09-13-2016, 03:16 AM
Please, use code tags !

Chris2460
09-13-2016, 04:44 AM
Please, use code tags !


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

Paul_Hossler
09-13-2016, 05:00 AM
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