View Single Post
  #18   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Making cells mandatory to fill in

Try this:

For Each cell In me.worksheets("MASTER").Range("d5,g5,j5,e7,m7,g10" )

Me refers to the object that owns the code. In this case, since the code is in
the ThisWorkbook module, the Me keyword refers to the workbook that's closing.

And in this case, it doesn't matter, but I like this syntax:

For Each cell In me.worksheets("MASTER").Range("d5,g5,j5,e7,m7,g10" ).cells

I think it makes it more self-documenting.


wkmooreh wrote:

Dave Thanks.. this is what i put. i saved it and closed it out , when back in
and it isnt forcing doing anything... I am sorry for the confusion, I did
this years ago. But none of it has come back to me at all

Option Explicit
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim cell As Range

For Each cell In
Expense_Report__BLANK.xls("MASTER").Range("d5,g5,j 5,e7,m7,g10")
If IsEmpty(cell.Value) Then
MsgBox "You must fill in cell " & cell.Address
Application.Goto cell
Cancel = True
Exit For
End If
Next cell
End Sub

--
w

"wkmooreh" wrote:

I need help, I am working on an excel expense report templete and want them
to fill in certain cells before they exit. When I copied the thread from
below I keep getting error messages. I dont know if I am putting valoues of
the cells i want filled out in the wrong place or not. This is what it looks
like: it says for each cell in range line is not right...

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)


Dim cell As Range


For Each cell In Range(d5, g5, j5, e7, m7, g10)


If IsEmpty(cell.Value) Then


MsgBox "You must fill in cell " & cell.Address


Application.Goto cell


Cancel = True


Exit For


End If


Next cell


End Sub

--
wkmooreh


"abfabrob" wrote:

I am creating an application form where I want users to fill certain cells in
before closing the document.

Does anyone have an idiots guide to doing this, cos I'm not great with excell.

ANY help welcome!!!


--

Dave Peterson