Save Button name in a variable

Hazelwood

New Member
Joined
Feb 25, 2018
Messages
13
In my procedure I save the value of a lookup data item as the name of a button.

ie.
member = Worksheets("Current Members").Cells(c, 1)


<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000 ; background-color: #ffffff}span.s1 {color: #011993}</style>With btn
.OnAction = "A02_AddAMember"
.Caption = member
.Name = "Btn" & 8
End With

Now I want to save the .caption value to another variable in another sub

ie. member2 = .caption value

But I cannot figure out how to do this.

Can anyone help me out?
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Hi,
pass the variable to your called procedure as an argument


example

Your procedure

Rich (BB code):
      Dim Member As String
    
    Member = Worksheets("Current Members").Cells(c, 1)
    
    With btn
    .OnAction = "A02_AddAMember"
    .Caption = Member
    .Name = "Btn" & 8
    End With
    
    MyCalledProcedure Member


the procedure you are calling

Rich (BB code):
Sub MyCalledProcedure(ByVal Caption As String)


        MsgBox Caption


End Sub


Hope Helpful


Dave
 
Upvote 0
Dave,

Upon review, I'm still stuck.

The above solution had the value in member already and we passed it to MyCalledProcedure member. I cannot save "A02_AddAMember" with a "(variable name)" as the .OnAction value (I tried to use Caption).

So I'm back to square one, how can a Button pass on the value of the .caption field when the .OnAction calls the sub?
 
Upvote 0
Hi,
post code you are having issue with.

Dave
 
Upvote 0
For c = 2 To LastMemberRow
If memberleft5 = Left(Worksheets("Current Members").Cells(c, 1), 5) Then
i = i + 1
Select Case i
Case 1
member1 = Worksheets("Current Members").Cells(c, 1)
Set t = ActiveSheet.Range(Cells(x + 10, y + 1), Cells(x + 11, y + 5))
Set btn = ActiveSheet.Buttons.Add(t.Left, t.Top, t.Width, t.Height)
With btn
.OnAction = "A03_UpdateAMember" & i
.Caption = Worksheets("Current Members").Cells(c, 1).Value
.Name = "Btn" & 1
End With
Case 2
member2 = Worksheets("Current Members").Cells(c, 1)
Set t = ActiveSheet.Range(Cells(x + 13, y + 1), Cells(x + 14, y + 5))
Set btn = ActiveSheet.Buttons.Add(t.Left, t.Top, t.Width, t.Height)
With btn
.OnAction = "A03_UpdateAMember" & i
.Caption = Worksheets("Current Members").Cells(c, 1).Value
.Name = "Btn" & 2
End With

etc ...

With the buttons on the worksheet, I will click on a button.

It will call the sub "A03_UpdateAMember" & i

I now need the value of .Caption as it has the lookup value I need to continue

Public Sub A03_UpdateAMember1()
'
member = .Caption (put this here to show what data value I want)
' the below sub will use member as the lookup value

Call A03c_PullCurrentMemberInfo
Call A03d_PullPaymentInfo
End Sub

<colgroup><col></colgroup><tbody>
</tbody>

<colgroup><col></colgroup><tbody>
</tbody>

Thank you for following up
 
Upvote 0
Hi,
You code is not fully clear but I am take it from the thread conversation that you want to pass the Button Caption to the procedure assigned to OnAction?

It has been awhile since I have used OnAction property but I think your will need to be modified as follows:

In your main procedure:

Code:
  With btn
        .Caption = Worksheets("Current Members").Cells(c, 1).Value
        .OnAction = "'A03_UpdateAMember" & i & """" & .Caption & """'"
        .Name = "Btn" & 2
    End With

note the change of Order in code structure where I have applied the Caption property FIRST as it is required in the OnAction property to pass to the assigned procedure.



In the procedure you are calling you will need to add a parameter to pass the caption to

Code:
Public Sub A03_UpdateAMember1(ByVal Caption As String)


MsgBox Caption
'
'member = .Caption (put this here to show what data value I want)
' the below sub will use member as the lookup value
Call A03c_PullCurrentMemberInfo
Call A03d_PullPaymentInfo
End Sub

Hope Helpful

Dave
 
Upvote 0

Forum statistics

Threads
1,214,635
Messages
6,120,660
Members
448,975
Latest member
sweeberry

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top