Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / September 2007

Tip: Looking for answers? Try searching our database.

Running Conditional If-then script off a command box

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bucs85027 - 17 Sep 2007 22:10 GMT
I am trying to set up a command box that will do two things conditionally if
clicked.  First, I want to run script 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!
jhyatt - 17 Sep 2007 22:32 GMT
sorry forgot to add this to the end of the code

Worksheets("sheet2").Range("b4").Activate
Bucs85027 - 17 Sep 2007 22:50 GMT
I will give this a shot.  Thank you!

> sorry forgot to add this to the end of the code
>
> Worksheets("sheet2").Range("b4").Activate
jhyatt - 17 Sep 2007 22:32 GMT
you could something like this just replace the cell value ie b1 with cells
that should contain the text.

Sub AnswerQuestion()
   If b1 = "" Then
       MsgBox "All questions must be answered"
           Worksheets("Sheet1").Range("b1").Activate
   ElseIf b4 = "" Then
       MsgBox "All questions must be answered"
           Worksheets("Sheet1").Range("b4").Activate
   End If
End Sub

> I am trying to set up a command box that will do two things conditionally if
> clicked.  First, I want to run script that will validate that text is
[quoted text clipped - 5 lines]
> If anyone can help with this, I would appreciate it!  I have been trying to
> figure this out for nearly a week!
jhyatt - 17 Sep 2007 22:32 GMT
is it all in one column. how many questions or how many cells are you looking
at

> I am trying to set up a command box that will do two things conditionally if
> clicked.  First, I want to run script that will validate that text is
[quoted text clipped - 5 lines]
> If anyone can help with this, I would appreciate it!  I have been trying to
> figure this out for nearly a week!
jhyatt - 17 Sep 2007 23:22 GMT
this should do the trick

Sub AnswerQuestion()
   Worksheets("Sheet1").Range("b1").Activate
   If ActiveCell.Value = "" Then
       MsgBox "All questions must be answered"
           Worksheets("Sheet1").Range("b1").Activate
   End If
   Worksheets("Sheet1").Range("b4").Activate
   If ActiveCell.Value = "" Then
       MsgBox "All questions must be answered"
           Worksheets("Sheet1").Range("b4").Activate
   Else
       ActiveWorkbook.Sheets("sheet2").Activate
           Worksheets("Sheet2").Range("b1").Activate
   End If
End Sub

> I am trying to set up a command box that will do two things conditionally if
> clicked.  First, I want to run script that will validate that text is
[quoted text clipped - 5 lines]
> If anyone can help with this, I would appreciate it!  I have been trying to
> figure this out for nearly a week!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.