View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
theDude[_16_] theDude[_16_] is offline
external usenet poster
 
Posts: 1
Default Make a cell required


You can use event macros in Excel to ensure a cell has an entry...

This macro will check to see if an entry exists in cell B5 if cell A
is less than zero EVERY TIME a change is made to the worksheet. I
both conditions are true, it alerts the user and then selects cell B
for the user to make an entry. Copy it to the code page of th
worksheet that needs the required entry in cell B5:

Code
-------------------
Private Sub Worksheet_Change(ByVal Target As Range)
' Check for value less than 0 in cell A5 & blank cell B5
' If both are true, alert user and select B5...
If Cells(5, 1) < 0 And Cells(5, 2) = "" Then
MsgBox "You must select a value for cell B5."
Cells(5, 2).Activate
End If
End Su
-------------------


Additionally, this macro will check to see if an entry exists in cel
B5 if cell A5 is less than zero whenever the user tries to CLOSE TH
WORKBOOK. If both conditions are true, it prevents the workbook fro
closing, alerts the user and then selects cell B5 for the user to mak
an entry. Copy it to the code page of the This Workbook object in th
file:

Code
-------------------
Private Sub Workbook_BeforeClose(Cancel As Boolean)
' Check for value less than 0 in cell A5 & blank cell B5
' If both are true, alert user and select B5...
If Cells(5, 1).Value < 0 And Cells(5, 2).Value = "" Then
Cancel = True
MsgBox "You must select a value for cell B5."
Cells(5, 2).Activate
End If
End Su
-------------------

Hope this helps,
theDud

--
theDud
-----------------------------------------------------------------------
theDude's Profile: http://www.excelforum.com/member.php...fo&userid=1655
View this thread: http://www.excelforum.com/showthread.php?threadid=38916