View Single Post
  #19   Report Post  
Posted to microsoft.public.excel.programming
JLGWhiz JLGWhiz is offline
external usenet poster
 
Posts: 3,986
Default Programming the Command button

Sheets("Draft Order Enrollee Record").Select Range("B1").Select

When you are selecting a new sheet and a range on that sheet, use two lines:

Sheets("Draft Order Enrollee Record").Select
Range("B1").Select

This applies to all of the lines in your code where you are using
Range("B1").Select This will reduce the likelyhood of generating error
messages and will ensure that Range B1 on the correct sheet is selected.
Otherwise, it could simply select B1 on the last active sheet and not send an
error message, so you would not know that an error had occurred.

"rink" wrote:

On Jan 30, 10:40 am, JLGWhiz
wrote:
I see dave has already fixed the code. I took a little more time to look at
it and realized the syntax was not correct. Here is what I was going to
suggest.

Sub InputButton_click()
'
' WDRIndOrder Macro
' Macro recorded 1/24/2008 by
'

'
If Range("0B2") = "WDR" And Range("B10") = "Individual" _
And Range("B14") = "Active" Then
Sheets("NPDES Ind Order").Select
Range("B1").Select
ElseIf Range("B2") = "NPDES Permits" And Range("B10") _
= "Individual" And Range("B14") = "Active" Then
Sheets("WDR Ind Order").Select
Range("B1").Select
ElseIf Range("B2") = "WAIVER" And Range("B10") = _
"Individual" And Range("B14") = "Active" Then
Sheets("WAIVER IND Order").Select
Range("B1").Select
ElseIf Range("B10") = "General" And Range("B14") _
= "Active" Then
Sheets("General Order").Select
Range("B1").Select
ElseIf Range("B2") = "ENROLLEE" And Range("B14") _
= "Active" Then
Sheets("Enrollee Record ").Select
Range("B1").Select
ElseIf Range("B14") = "Draft" Then
Sheets("Draft Order-Enrollee Record").Select
Range("B1").Select
End If
End Sub



"rink" wrote:
On Jan 30, 9:48 am, JLGWhiz wrote:
Did you get the button from the Forms toolbar or the Control Toolbox? If
from the Forms toolbar, the Macro has to be attached through the Assign Macro
dialog box. If from the control toolbox then the button has Its own code
module which is accessed by double clicking in design mode. You probably
already knew this, but just to be sure all bases are covered.


"rink" wrote:
On Jan 30, 8:48 am, JLGWhiz wrote:
If you did not name the CommandButton "InputButton" then it will not work.
You can use CommandButton1_Click if it is the only button. Or make sure the
Name is changed in the properties window. The caption is not the name.


" wrote:
Hello,


Maybe someone can tell me what I am doing wrong. I wrote the
following Macro and it appears to run correctly, however when I assign
it to the command button, nothing executes. The button clicks but
doesnt take you to the assigned sheet. You help is much appreciated.


Sub InputButton_click()
'
' WDRIndOrder Macro
' Macro recorded 1/24/2008 by
'


'
If ("B2" = "WDR") And ("B10" = "Individual") And ("B14" =
"Active") Then
Sheets("NPDES Ind Order").Select("B1").Select
ElseIf ("B2" = "NPDES Permits") And ("B10" = "Individual") And
("B14" = "Active") Then
Sheets("WDR Ind Order").Select("B1").Select
ElseIf ("B2" = "WAIVER") And ("B10" = "Individual") And ("B14" =
"Active") Then
Sheets("WAIVER IND Order").Select("B1").Select
ElseIf ("B10" = "General") And ("B14" = "Active") Then
Sheets("General Order").Select("B1").Select
ElseIf ("B2" = "ENROLLEE") And ("B14" = "Active") Then
Sheets("Enrollee Record ").Select("B1").Select
ElseIf ("B14" = "Draft") Then
Sheets("Draft Order-Enrollee Record").Select("B1").Select
End If
End Sub- Hide quoted text -


- Show quoted text -


I edited the button and renamed it InputButton and assigned the Macro
abovebut it doesn't take me anywhere. The cells I reference in the
code have dropdown choices, would that make a difference?- Hide quoted text -


- Show quoted text -


I've tried both Buttons. I copied the code over on the Command Button
and just assigned theMacro on the Button. Neither take you anywhere.
Just for the heck of it, I added another command at the end that said
Range("B18").Select
and the button changed to that cell on the worksheet with the button
so I don't know what is going on.. I closed the worksheet without
saving so the added code would not save.- Hide quoted text -


- Show quoted text -


Ok, I fixed the code as follows and it runs except for the last 2
commands. Thanks for all of your help..

Sub InputButton_click()
'
' WDRIndOrder Macro
' Macro recorded 1/24/2008 by DAS Staff
'

'
If Range("B2") = "WDR" And Range("B10") = "Individual" And
Range("B14") = "Active" Then
Sheets("WDR Ind Order").Select Range("B1").Select
ElseIf Range("B2") = "NPDES Permits" And Range("B10") =
"Individual" And Range("B14") = "Active" Then
Sheets("NPDES Ind Order").Select Range("B1").Select
ElseIf Range("B2") = "WAIVER" And Range("B10") = "Individual" And
Range("B14") = "Active" Then
Sheets("WAIVER IND Order").Select Range("B1").Select
ElseIf Range("B10") = "General" And Range("B14") = "Active" Then
Sheets("General Order").Select Range("B1").Select
ElseIf Range("B2") = "ENROLLEE" And Range("B14") = "Active" Then
Sheets("Enrollee").Select Range("B1").Select
ElseIf Range("B14") = "Draft" Then
Sheets("Draft Order Enrollee Record").Select Range("B1").Select
End If
End Sub