Setting up an If-Then condition off of a command box

B

Bucs85027

I am trying to set up a command box that will do two things conditionally if
clicked. First, I want to run a macro that will validate that text is
present in a range of cells (all cells must have text values, although the
text values may vary). If all of the cells in the range contain text, then
the command button will take the user to the next sheet. If all the cells in
the range do not have text, the command button will spawn a message box
informing the user that all questions must be answered in order to continue.
If anyone can help with this, I would appreciate it! I have been trying to
figure this out for nearly a week!
 
G

Gary''s Student

Here is an example in which the user must fill in all the cells from A1 thru
A10:

1. first create a button using the Forms menu
2. assign the following macro to the button:

Sub empty_check()
Set r = Range("A1:A10")
n = Application.WorksheetFunction.CountA(r)
If n < 10 Then
MsgBox ("A1 thru A10 must fill filled in")
Exit Sub
Else
Sheets("Sheet2").Activate
Range("A1").Select
End If
End Sub

Adapt it to suite your range of cells
 

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