Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have a button whose click event invokes 2 Input Boxes. The input boxes ask
the user for the first and last name of a person. The input boxes have an OK and a Cancel button on them. If the user clicks on either of the Cancel buttons, I want the programming to stop and place the cursor in a specified cell. I tried to do this on my own, but I haven't had any success. With or without my "Cancel" coding, the sub runs in it's entirety and creates a name in my list with just a comma in it. How do I get the Cancel button click (whether it is the first input box or the second input box) to discontinue running the macro and move the user's cursor to cell AG3? Here is the coding I have written so far: If CommandButtonAddForeman.Caption = "Cancel" Then EndRoutine Dim AnswerForemenFirst As String Dim AnswerForemenLast As String AnswerForemenFirst = InputBox("What is the Foreman's first name?", "Add a new Foreman") AnswerForemanLast = InputBox("What is the Foreman's last name?", "Add a new Foreman") Application.Goto Reference:="markerforemanadd" ActiveCell.Value = "zzzzzz" Selection.EntireRow.Insert ActiveCell.Value = AnswerForemanLast + ", " + AnswerForemenFirst ActiveCell.Offset(0, 1).Select ActiveCell.FormulaR1C1 = "=RC[-1]" Application.Goto Reference:="ForemenToSort" Selection.Sort Key1:=Range("SortRangeColumn"), Order1:=xlAscending, Header:=xlNo, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom Application.Goto Reference:="markerforemanadd" ActiveCell.Value = " " Range("A1").Select Range("AG3").Select Private Sub EndRoutine() Range("AG3").Select End End Sub Thanks for any help you can offer. Tofer |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
If CommandButtonAddForeman.Caption = "Cancel" Then EndRoutine
Dim AnswerForemenFirst As String Dim AnswerForemenLast As String AnswerForemenFirst = InputBox("What is the Foreman's first name?", _ "Add a new Foreman") If AnswerForemenFirst = "" Then Exit Sub AnswerForemenLast = InputBox("What is the Foreman's last name?", _ "Add a new Foreman") If AnswerForemenLast = "" Then Exit Sub Application.Goto Reference:="markerforemanadd" ActiveCell.Value = "zzzzzz" Selection.EntireRow.Insert ActiveCell.Value = AnswerForemenLast + ", " + AnswerForemenFirst ActiveCell.Offset(0, 1).Select ActiveCell.FormulaR1C1 = "=RC[-1]" Application.Goto Reference:="ForemenToSort" Selection.Sort Key1:=Range("SortRangeColumn"), _ Order1:=xlAscending, _ Header:=xlNo, _ OrderCustom:=1, _ MatchCase:=False, _ Orientation:=xlTopToBottom Application.Goto Reference:="markerforemanadd" ActiveCell.Value = " " Range("A1").Select Range("AG3").Select -- HTH Bob Phillips (remove nothere from the email address if mailing direct) "ToferKing" wrote in message ... I have a button whose click event invokes 2 Input Boxes. The input boxes ask the user for the first and last name of a person. The input boxes have an OK and a Cancel button on them. If the user clicks on either of the Cancel buttons, I want the programming to stop and place the cursor in a specified cell. I tried to do this on my own, but I haven't had any success. With or without my "Cancel" coding, the sub runs in it's entirety and creates a name in my list with just a comma in it. How do I get the Cancel button click (whether it is the first input box or the second input box) to discontinue running the macro and move the user's cursor to cell AG3? Here is the coding I have written so far: If CommandButtonAddForeman.Caption = "Cancel" Then EndRoutine Dim AnswerForemenFirst As String Dim AnswerForemenLast As String AnswerForemenFirst = InputBox("What is the Foreman's first name?", "Add a new Foreman") AnswerForemanLast = InputBox("What is the Foreman's last name?", "Add a new Foreman") Application.Goto Reference:="markerforemanadd" ActiveCell.Value = "zzzzzz" Selection.EntireRow.Insert ActiveCell.Value = AnswerForemanLast + ", " + AnswerForemenFirst ActiveCell.Offset(0, 1).Select ActiveCell.FormulaR1C1 = "=RC[-1]" Application.Goto Reference:="ForemenToSort" Selection.Sort Key1:=Range("SortRangeColumn"), Order1:=xlAscending, Header:=xlNo, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom Application.Goto Reference:="markerforemanadd" ActiveCell.Value = " " Range("A1").Select Range("AG3").Select Private Sub EndRoutine() Range("AG3").Select End End Sub Thanks for any help you can offer. Tofer |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Bob, you solved it!
Thank you so much for your help. Tofer "Bob Phillips" wrote: If CommandButtonAddForeman.Caption = "Cancel" Then EndRoutine Dim AnswerForemenFirst As String Dim AnswerForemenLast As String AnswerForemenFirst = InputBox("What is the Foreman's first name?", _ "Add a new Foreman") If AnswerForemenFirst = "" Then Exit Sub AnswerForemenLast = InputBox("What is the Foreman's last name?", _ "Add a new Foreman") If AnswerForemenLast = "" Then Exit Sub Application.Goto Reference:="markerforemanadd" ActiveCell.Value = "zzzzzz" Selection.EntireRow.Insert ActiveCell.Value = AnswerForemenLast + ", " + AnswerForemenFirst ActiveCell.Offset(0, 1).Select ActiveCell.FormulaR1C1 = "=RC[-1]" Application.Goto Reference:="ForemenToSort" Selection.Sort Key1:=Range("SortRangeColumn"), _ Order1:=xlAscending, _ Header:=xlNo, _ OrderCustom:=1, _ MatchCase:=False, _ Orientation:=xlTopToBottom Application.Goto Reference:="markerforemanadd" ActiveCell.Value = " " Range("A1").Select Range("AG3").Select -- HTH Bob Phillips (remove nothere from the email address if mailing direct) "ToferKing" wrote in message ... I have a button whose click event invokes 2 Input Boxes. The input boxes ask the user for the first and last name of a person. The input boxes have an OK and a Cancel button on them. If the user clicks on either of the Cancel buttons, I want the programming to stop and place the cursor in a specified cell. I tried to do this on my own, but I haven't had any success. With or without my "Cancel" coding, the sub runs in it's entirety and creates a name in my list with just a comma in it. How do I get the Cancel button click (whether it is the first input box or the second input box) to discontinue running the macro and move the user's cursor to cell AG3? Here is the coding I have written so far: If CommandButtonAddForeman.Caption = "Cancel" Then EndRoutine Dim AnswerForemenFirst As String Dim AnswerForemenLast As String AnswerForemenFirst = InputBox("What is the Foreman's first name?", "Add a new Foreman") AnswerForemanLast = InputBox("What is the Foreman's last name?", "Add a new Foreman") Application.Goto Reference:="markerforemanadd" ActiveCell.Value = "zzzzzz" Selection.EntireRow.Insert ActiveCell.Value = AnswerForemanLast + ", " + AnswerForemenFirst ActiveCell.Offset(0, 1).Select ActiveCell.FormulaR1C1 = "=RC[-1]" Application.Goto Reference:="ForemenToSort" Selection.Sort Key1:=Range("SortRangeColumn"), Order1:=xlAscending, Header:=xlNo, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom Application.Goto Reference:="markerforemanadd" ActiveCell.Value = " " Range("A1").Select Range("AG3").Select Private Sub EndRoutine() Range("AG3").Select End End Sub Thanks for any help you can offer. Tofer |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
vb cancel button | Excel Programming | |||
Cancel button to cancel the whole macro | Excel Programming | |||
how do I make a routine run after the 'cancel' butten is pressed . | Excel Programming | |||
Cancel button | Excel Programming | |||
Cancel Button | Excel Programming |