require cell input before macro can run

T

TBoy 1701

I have a macro that runs from a textbox click. I would like to require a cell
(say b19)
have data entered in it before the macro can run. I am having issues with
folks running the macro before all of the data is entered.
 
D

Dave Peterson

You can add a check near the top of your subroutine:

Option Explicit
Sub Testme01()
'declarations

'your check
if isempty(activesheet.range("b19").value) then
msgbox "Please enter your data"
exit sub
end if

'rest of code here

End Sub
 
J

JLGWhiz

You might want to look at using Data Validation in cell B19 to make sure it
has the correct data in it, then you could use an If ... then statement in
in your textbox event code to check the content of B19:

Set sh = ActiveSheet
If sh .Range("B19"') <> "" Then
'You existing code here
End If

Without the data validation, a user could enter any data into the cell and
the textbox event code would still run.
 
B

B Lynn B

I've solved this problem in one of my user files by making a named range of
all the cells that are "required" entry (and enforce some data validation
rules on them). then:

Sub RunMyCode()

Dim GoAhead as Boolean
Dim CL as range

GoAhead = True
For Each CL in Range("Required").Cells
If CL = "" Then GoAhead = False
Next CL

If GoAhead = False Then
MsgBox "Please enter all required data."
Exit Sub
End If

'then whatever code you want to run if the required data is present.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top