Checking cells are filled in.

  • Thread starter Thread starter SunGod
  • Start date Start date
S

SunGod

From what I've seen being asked on these forums this question sound
like n00bish. But is it possible to check that certan cells are fille
in and if they are not an error message pops up. I am planning to use
macro if its possible and put this into a print sheet button, so firs
it checks to see that the cells are filled in and then if they ar
filled in prints the sheet. This is coursework and for some reason w
aren't given marks for anything acheived using VB scripting so I'd lik
to use a macro. But if it isnt possible then VB would be fine.

Thanks alot in advance :
 
Hi SunGod
Here's a sample code to amend accordingly:
Dim EmptyCells As Long, StopIt As Boolean
EmptyCells = 0
For Each cel In Range("MyListOfCells")
If cel.Value = "" Then
MsgBox "Cell " & cel.Address & " has no input", vbInformation,
"Macro will be stopped"
EmptyCells = EmptyCells + 1
End If
Next cel
If EmptyCells <> 0 Then StopIt = True
If StopIt Then
MsgBox "Macro is now stopped", vbInformation, "For Info"
Exit Sub
Else
ActiveSheet.PrintOut
End If

HTH
Cordially
Pascal
 
One way:

Public Sub PrintSheet()
Dim rCheck As Range
Dim rCell As Range
Dim i As Long
Dim sMsg As String

Set rCheck = Sheets("Sheet1").Range("A1,B4,J7,J10")
With rCheck
For Each rCell In rCheck
If IsEmpty(rCell.Value) Then _
sMsg = sMsg & ", " & rCell.Address(False, False)
Next rCell
If Len(sMsg) > 0 Then
MsgBox "Need to fill in cell(s): " & Mid(sMsg, 3)
Else
.Parent.PrintOut
End If
End With
End Sub
 
Back
Top