Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MsgBox for missing cell values 2

Status
Not open for further replies.

DrMingle

Technical User
May 24, 2009
116
US
I'm sorry I can't even show code...I don't know where to start.

Below is the current code (which is fine)...but I am missing the MsgBox components.

Sub SaveAsNameDateScore()
ThisFile = Range("B2").Text & " " & Replace(Range("B5").Text, "/", "-") & " " & Range("C18").Text
ActiveWorkbook.SaveAs Filename:=ThisFile
End Sub

I want there to be a MsgBox pop up if any of the cell values are empty (B2, B5, C18)...I would like for them to be individually prompted. For example...

(B2)MsgBox should read --> Please enter Specialist Name.
(B5)MsgBox should read --> Please enter Audit Completed Date.
(C18)MsgBox should read --> Please enter Average Quality Score.

I simply want the MsgBox to inform, for the user to click OK, and for the macro to exit (or not SaveAs) until the user fixes the errors...

 


Hi,
Code:
If [B2] = "" Then
  MsgBox "Please enter Specialist Name in B2"
  Exit Sub
End If


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Skip:
Was I supposed to do the below...?
I want to be sure I don't SaveAs with missing cell values...the current suggestion allows me to SaveAs and prompts afterword....

Sub SaveAsNameDateScore()
ThisFile = Range("B2").Text & " " & Replace(Range("B5").Text, "/", "-") & " " & Range("C18").Text
ActiveWorkbook.SaveAs Filename:=ThisFile
If [B2] = "" Then
MsgBox "Please enter Specialist Name"
Exit Sub
If [B5] = "" Then
MsgBox "Please enter Audit Completed Date"
Exit Sub
If [c18] = "" Then
MsgBox "Please enter Average Quality Score"
Exit Sub
End If
End Sub
 



why would you assemble the file name and save as BEFORE checking each cell?

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Your correct.

I want to have the macro check each cell before Save As...

I'm just not sure how to pull that off...
 
I keep running into this as well...

Compile error Block if without end if

I'm sure this is simple, but it's beyond me.
 
Code:
Sub SaveAsNameDateScore()
If Trim(Range("B2")) = "" Then
  MsgBox "Please enter Specialist Name"
  Exit Sub
End If
If Not IsDate(Range("B5")) Then
  MsgBox "Please enter Audit Completed Date"
  Exit Sub
End If
If Not IsNumeric(Range("C15")) Then
  MsgBox "Please enter Average Quality Score"
  Exit Sub
End If
ThisFile = Range("B2").Text & " " & Replace(Range("B5").Text, "/", "-") & " " & Range("C18").Text
ActiveWorkbook.SaveAs Filename:=ThisFile
End Sub

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top