Error message if any of 3 cells are blank

AndyB63UK

New Member
Joined
Oct 5, 2011
Messages
47
On a spreadsheet I have a "Save" button which saves the sheet in a specific place determined by the contents of 3 cells.
C4 = Date, E4 = Venue, I4 = Name
These three cells determine the location and name the file will be saved; c:\Venue\Year (from C4)\Month (from C4)\Name (a combination of day from C4 and name)

Can I add an IF statement in the code for the save button that pops up an error message if any 1 of the 3 cells are blank?
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
I haven't studied your existing code, but this should be a fairly simple way to confirm the cells are complete.
It's also easily expandable if your decide there are more (or less) required cells.

Code:
Private Sub SaveSR_Click()
  Dim MyPath  As String
  Dim MyArr   As Variant
  Dim pNum    As Long
  Dim pBuf    As String
  Dim ReqCells As Range
  
  Set ReqCells = Range("C4, E4, I4") '<- Add/reduce as needed
  
  If WorksheetFunction.CountA(ReqCells) = ReqCells.Cells.Count Then
  
    'Rest of your existing code goes here
  
  Else
    MsgBox "All the following cells must be completed: " & ReqCells.Address(0, 0)
  End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,597
Messages
6,125,738
Members
449,255
Latest member
whatdoido

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top