Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 470
Default Commandbutton question

I have a worksheet that has 12 different sections (one for each month) used
to enter data to balance a checkbook. I use a commandbutton for each month.
I am not quite sure how to explain what I want to do so I will use the
"normal" code and the the code I have to replace the normal code. Then I
will ask the question.

NORMAL CODE

Private Sub CommandButton1_Click()
Application.Goto Reference:="JAN08"
End Sub

NEW CODE TO DO THE SAME THING

Private Sub CommandButton1_Click()
Dim mnth As String
mnth = CommandButton1.Caption & "08"
Application.Goto Reference:=mnth
End Sub

The caption is the first three letters of each month (JAN, FEB, MAR, etc.)
The cell name for each month is JAN08, FEB08, etc.

Here is my question. Is there a way to determine which commandbutton was
clicked so that I do not have to edit each of the 12 macros and change the
numerical value of each commandbutton within the subroutine?

I was trying to pull out the "name", just as I did with caption, and then do
a RIGHT function and get the number. In the properties of each commandbutton
is "(NAME)". I was not sure if I could access that field.

Thanks,
Les

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,420
Default Commandbutton question

If they are Forms buttons

Private Sub Button1_Click()
Dim mnth As String
mnth = ActiveSheet.Buttons(Application.Caller).Caption & "08"
Application.Goto Reference:=mnth
End Sub

--
__________________________________
HTH

Bob

"WLMPilot" wrote in message
...
I have a worksheet that has 12 different sections (one for each month) used
to enter data to balance a checkbook. I use a commandbutton for each
month.
I am not quite sure how to explain what I want to do so I will use the
"normal" code and the the code I have to replace the normal code. Then I
will ask the question.

NORMAL CODE

Private Sub CommandButton1_Click()
Application.Goto Reference:="JAN08"
End Sub

NEW CODE TO DO THE SAME THING

Private Sub CommandButton1_Click()
Dim mnth As String
mnth = CommandButton1.Caption & "08"
Application.Goto Reference:=mnth
End Sub

The caption is the first three letters of each month (JAN, FEB, MAR, etc.)
The cell name for each month is JAN08, FEB08, etc.

Here is my question. Is there a way to determine which commandbutton was
clicked so that I do not have to edit each of the 12 macros and change the
numerical value of each commandbutton within the subroutine?

I was trying to pull out the "name", just as I did with caption, and then
do
a RIGHT function and get the number. In the properties of each
commandbutton
is "(NAME)". I was not sure if I could access that field.

Thanks,
Les



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 470
Default Commandbutton question

What do you mean by Forms buttons? I am just using commandbuttons1 -
commandbutton12.

Les

"Bob Phillips" wrote:

If they are Forms buttons

Private Sub Button1_Click()
Dim mnth As String
mnth = ActiveSheet.Buttons(Application.Caller).Caption & "08"
Application.Goto Reference:=mnth
End Sub

--
__________________________________
HTH

Bob

"WLMPilot" wrote in message
...
I have a worksheet that has 12 different sections (one for each month) used
to enter data to balance a checkbook. I use a commandbutton for each
month.
I am not quite sure how to explain what I want to do so I will use the
"normal" code and the the code I have to replace the normal code. Then I
will ask the question.

NORMAL CODE

Private Sub CommandButton1_Click()
Application.Goto Reference:="JAN08"
End Sub

NEW CODE TO DO THE SAME THING

Private Sub CommandButton1_Click()
Dim mnth As String
mnth = CommandButton1.Caption & "08"
Application.Goto Reference:=mnth
End Sub

The caption is the first three letters of each month (JAN, FEB, MAR, etc.)
The cell name for each month is JAN08, FEB08, etc.

Here is my question. Is there a way to determine which commandbutton was
clicked so that I do not have to edit each of the 12 macros and change the
numerical value of each commandbutton within the subroutine?

I was trying to pull out the "name", just as I did with caption, and then
do
a RIGHT function and get the number. In the properties of each
commandbutton
is "(NAME)". I was not sure if I could access that field.

Thanks,
Les




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,420
Default Commandbutton question

What commandbuttons 1-12? On a userform? From the control toolbox? or
something else?

--
__________________________________
HTH

Bob

"WLMPilot" wrote in message
...
What do you mean by Forms buttons? I am just using commandbuttons1 -
commandbutton12.

Les

"Bob Phillips" wrote:

If they are Forms buttons

Private Sub Button1_Click()
Dim mnth As String
mnth = ActiveSheet.Buttons(Application.Caller).Caption & "08"
Application.Goto Reference:=mnth
End Sub

--
__________________________________
HTH

Bob

"WLMPilot" wrote in message
...
I have a worksheet that has 12 different sections (one for each month)
used
to enter data to balance a checkbook. I use a commandbutton for each
month.
I am not quite sure how to explain what I want to do so I will use the
"normal" code and the the code I have to replace the normal code. Then
I
will ask the question.

NORMAL CODE

Private Sub CommandButton1_Click()
Application.Goto Reference:="JAN08"
End Sub

NEW CODE TO DO THE SAME THING

Private Sub CommandButton1_Click()
Dim mnth As String
mnth = CommandButton1.Caption & "08"
Application.Goto Reference:=mnth
End Sub

The caption is the first three letters of each month (JAN, FEB, MAR,
etc.)
The cell name for each month is JAN08, FEB08, etc.

Here is my question. Is there a way to determine which commandbutton
was
clicked so that I do not have to edit each of the 12 macros and change
the
numerical value of each commandbutton within the subroutine?

I was trying to pull out the "name", just as I did with caption, and
then
do
a RIGHT function and get the number. In the properties of each
commandbutton
is "(NAME)". I was not sure if I could access that field.

Thanks,
Les






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 470
Default Commandbutton question

From the control toolbox. I am not using a userform.

Les


"Bob Phillips" wrote:

What commandbuttons 1-12? On a userform? From the control toolbox? or
something else?

--
__________________________________
HTH

Bob

"WLMPilot" wrote in message
...
What do you mean by Forms buttons? I am just using commandbuttons1 -
commandbutton12.

Les

"Bob Phillips" wrote:

If they are Forms buttons

Private Sub Button1_Click()
Dim mnth As String
mnth = ActiveSheet.Buttons(Application.Caller).Caption & "08"
Application.Goto Reference:=mnth
End Sub

--
__________________________________
HTH

Bob

"WLMPilot" wrote in message
...
I have a worksheet that has 12 different sections (one for each month)
used
to enter data to balance a checkbook. I use a commandbutton for each
month.
I am not quite sure how to explain what I want to do so I will use the
"normal" code and the the code I have to replace the normal code. Then
I
will ask the question.

NORMAL CODE

Private Sub CommandButton1_Click()
Application.Goto Reference:="JAN08"
End Sub

NEW CODE TO DO THE SAME THING

Private Sub CommandButton1_Click()
Dim mnth As String
mnth = CommandButton1.Caption & "08"
Application.Goto Reference:=mnth
End Sub

The caption is the first three letters of each month (JAN, FEB, MAR,
etc.)
The cell name for each month is JAN08, FEB08, etc.

Here is my question. Is there a way to determine which commandbutton
was
clicked so that I do not have to edit each of the 12 macros and change
the
numerical value of each commandbutton within the subroutine?

I was trying to pull out the "name", just as I did with caption, and
then
do
a RIGHT function and get the number. In the properties of each
commandbutton
is "(NAME)". I was not sure if I could access that field.

Thanks,
Les









  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,420
Default Commandbutton question

Create a class module named clsActiveXEvents with the following code

Option Explicit

Public WithEvents mButtonGroup As MSForms.CommandButton

Private Sub mButtonGroup_Click()
Dim mnth As String
mnth = mButtonGroup.Caption & "08"
Application.Goto Reference:=mnth
End Sub


and in the worksheet module, add

Option Explicit

Dim mcolEvents As Collection

Private Sub Worksheet_Activate()
Dim cBtnEvents As clsActiveXEvents
Dim shp As Shape

Set mcolEvents = New Collection

For Each shp In Me.Shapes
If shp.Type = msoOLEControlObject Then
If TypeOf shp.OLEFormat.Object.Object Is MSForms.CommandButton
Then
Set cBtnEvents = New clsActiveXEvents
Set cBtnEvents.mButtonGroup = shp.OLEFormat.Object.Object
mcolEvents.Add cBtnEvents
End If
End If
Next

End Sub


--
__________________________________
HTH

Bob

"WLMPilot" wrote in message
...
From the control toolbox. I am not using a userform.

Les


"Bob Phillips" wrote:

What commandbuttons 1-12? On a userform? From the control toolbox? or
something else?

--
__________________________________
HTH

Bob

"WLMPilot" wrote in message
...
What do you mean by Forms buttons? I am just using commandbuttons1 -
commandbutton12.

Les

"Bob Phillips" wrote:

If they are Forms buttons

Private Sub Button1_Click()
Dim mnth As String
mnth = ActiveSheet.Buttons(Application.Caller).Caption & "08"
Application.Goto Reference:=mnth
End Sub

--
__________________________________
HTH

Bob

"WLMPilot" wrote in message
...
I have a worksheet that has 12 different sections (one for each
month)
used
to enter data to balance a checkbook. I use a commandbutton for
each
month.
I am not quite sure how to explain what I want to do so I will use
the
"normal" code and the the code I have to replace the normal code.
Then
I
will ask the question.

NORMAL CODE

Private Sub CommandButton1_Click()
Application.Goto Reference:="JAN08"
End Sub

NEW CODE TO DO THE SAME THING

Private Sub CommandButton1_Click()
Dim mnth As String
mnth = CommandButton1.Caption & "08"
Application.Goto Reference:=mnth
End Sub

The caption is the first three letters of each month (JAN, FEB, MAR,
etc.)
The cell name for each month is JAN08, FEB08, etc.

Here is my question. Is there a way to determine which
commandbutton
was
clicked so that I do not have to edit each of the 12 macros and
change
the
numerical value of each commandbutton within the subroutine?

I was trying to pull out the "name", just as I did with caption, and
then
do
a RIGHT function and get the number. In the properties of each
commandbutton
is "(NAME)". I was not sure if I could access that field.

Thanks,
Les









  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 320
Default Commandbutton question

look at Application.Caller
Put a Msgbox Application.Caller in the code of the button so you can see
what it returns to you - you can probably take advantage of that in one
subroutine.

"WLMPilot" wrote:

I have a worksheet that has 12 different sections (one for each month) used
to enter data to balance a checkbook. I use a commandbutton for each month.
I am not quite sure how to explain what I want to do so I will use the
"normal" code and the the code I have to replace the normal code. Then I
will ask the question.

NORMAL CODE

Private Sub CommandButton1_Click()
Application.Goto Reference:="JAN08"
End Sub

NEW CODE TO DO THE SAME THING

Private Sub CommandButton1_Click()
Dim mnth As String
mnth = CommandButton1.Caption & "08"
Application.Goto Reference:=mnth
End Sub

The caption is the first three letters of each month (JAN, FEB, MAR, etc.)
The cell name for each month is JAN08, FEB08, etc.

Here is my question. Is there a way to determine which commandbutton was
clicked so that I do not have to edit each of the 12 macros and change the
numerical value of each commandbutton within the subroutine?

I was trying to pull out the "name", just as I did with caption, and then do
a RIGHT function and get the number. In the properties of each commandbutton
is "(NAME)". I was not sure if I could access that field.

Thanks,
Les

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 470
Default Commandbutton question

I typed in "MsgBox Application.Caller" (without quotes) and got a Type Mismatch

Les

"Bob Umlas, Excel MVP" wrote:

look at Application.Caller
Put a Msgbox Application.Caller in the code of the button so you can see
what it returns to you - you can probably take advantage of that in one
subroutine.

"WLMPilot" wrote:

I have a worksheet that has 12 different sections (one for each month) used
to enter data to balance a checkbook. I use a commandbutton for each month.
I am not quite sure how to explain what I want to do so I will use the
"normal" code and the the code I have to replace the normal code. Then I
will ask the question.

NORMAL CODE

Private Sub CommandButton1_Click()
Application.Goto Reference:="JAN08"
End Sub

NEW CODE TO DO THE SAME THING

Private Sub CommandButton1_Click()
Dim mnth As String
mnth = CommandButton1.Caption & "08"
Application.Goto Reference:=mnth
End Sub

The caption is the first three letters of each month (JAN, FEB, MAR, etc.)
The cell name for each month is JAN08, FEB08, etc.

Here is my question. Is there a way to determine which commandbutton was
clicked so that I do not have to edit each of the 12 macros and change the
numerical value of each commandbutton within the subroutine?

I was trying to pull out the "name", just as I did with caption, and then do
a RIGHT function and get the number. In the properties of each commandbutton
is "(NAME)". I was not sure if I could access that field.

Thanks,
Les

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
CommandButton Focus Question [email protected] Excel Programming 1 May 18th 07 04:09 AM
how to get commandbutton name Sean Excel Programming 2 October 17th 06 08:49 AM
CommandButton Question Magnivy Excel Programming 5 June 8th 06 05:44 PM
Simpel commandbutton question Andy T via OfficeKB.com Excel Programming 3 September 8th 05 06:39 PM
Simple Question: Hiding a CommandButton JasperBlaas Excel Programming 3 August 9th 04 01:28 PM


All times are GMT +1. The time now is 10:19 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"