View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Jock Jock is offline
external usenet poster
 
Posts: 440
Default Making cells mandatory to fill in

Hi Gary,
Unfortunately, I can't get this to work. Could this be because the "Dim old
row as long" appears outside the sub - I get an error message stating that
only comments may appear outside.


Cheers
--
Traa Dy Liooar

Jock


"Gary''s Student" wrote:

Put this event macro in the worksheet code area:

Dim oldrow As Long
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If oldrow = 0 Then
oldrow = Target.Row
Exit Sub
End If
newrow = Target.Row
If newrow <= oldrow Then Exit Sub
If IsEmpty(Cells(oldrow, "D")) Or IsEmpty(Cells(oldrow, "H")) Or
IsEmpty(Cells(oldrow, "E")) Then
MsgBox ("must fill in D, E, and H of the previous row")
Application.EnableEvents = False
Cells(oldrow, "D").Select
Application.EnableEvents = True
Else
oldrow = newrow
End If
End Sub


Because it is worksheet code, it is very easy to install and use:

1. right-click the tab name near the bottom of the window
2. select View Code - this brings up a VBE window
3. paste the stuff in and close the VBE window

If you save the workbook, the macro will be saved with it.

To remove the macro:

1. bring up the VBE windows as above
2. clear the code out
3. close the VBE window

To learn more about macros in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

To learn more about Event Macros (worksheet code), see:

http://www.mvps.org/dmcritchie/excel/event.htm

--
Gary''s Student - gsnu200839


"Jock" wrote:

I need to ensure that certain cells in every row are filled in by the user.
How can I add code to force data input into, say, columns D, E and H when
the user navigates to the next row? Perhaps a popup box informing the user
and highlight the empty cell(s) in yellow for instance? Can the user then not
be able to continue until the empty cell(s) are filled in?

Thanks,
--
Traa Dy Liooar

Jock