Command button link another command button userform

THE_NEW_XL_GUY

New Member
Joined
Dec 20, 2017
Messages
47
Hi guys, am new to this VBA useforms, need help in linking one command button which performs some function and i want that button value to be linked to another button. Ex: I have button in userform which open dialogue box to select a workbook and find max value in it . This value must to be sent to workbook when I click submit button in userform. Need help in this. Really appreciate.
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
if you right click the button and assign macro then point it to the macro that runs from the other button
 
Upvote 0
thank you replying. I don't quite understand answer. I need value from Cmd_tt_Click() [[maximum no in row ]] to be copied/called inside cmd_submit_Click() and to be pasted in range D13.

here is my code:

Private Sub cmd_submit_Click()
Dim tt_object
Range("E13").value = TextBox1.Text
Range("E14").value = TextBox2.Text
Range("E15").value = TextBox3.Text
Range("E16").value = TextBox4.Text
Range("B11").value = textbox5.Text
Range("D13").value = ??? how to call the below cmd button value here ??

End Sub

Private Sub Cmd_tt_Click()

Dim fNameAndPath As Variant, wb As Workbook, max_num As Variant, ws As Worksheet

fNameAndPath = Application.GetOpenFilename(FileFilter:="Excel Files (*.CSV), *.CSV", Title:="Select File To Be Opened")
If fNameAndPath = False Then Exit Sub
Set wb = Workbooks.Open(fNameAndPath)
max_num = Application.WorksheetFunction.Max(Range("B2:B10"))

wb.Close savechanges:=True 'or false
End Sub
 
Upvote 0
please let me know if you need anything else. am working in userforms I want that data to be copied when I press cmd_submit_Click().
 
Upvote 0
Try it like this
Code:
Option Explicit
[COLOR=#ff0000]Dim max_num As Variant[/COLOR]

Private Sub cmd_submit_Click()

Range("E13").Value = TextBox1.Text
Range("E14").Value = textbox2.Text
Range("E15").Value = textbox3.Text
Range("E16").Value = TextBox4.Text
Range("B11").Value = textbox5.Text
Range("D13").Value = max_num

End Sub

Private Sub Cmd_tt_Click()

Dim fNameAndPath As Variant, wb As Workbook, ws As Worksheet

fNameAndPath = Application.GetOpenFilename(FileFilter:="Excel Files (*.CSV), *.CSV", title:="Select File To Be Opened")
If fNameAndPath = False Then Exit Sub
Set wb = Workbooks.Open(fNameAndPath)
max_num = Application.WorksheetFunction.Max(Range("B2:B10"))

wb.Close savechanges:=True 'or false
End Sub
Where the Dim statement in red is at the top of the module, before any code. Also remove it from the Private Sub Cmd_tt_Click code.
 
Upvote 0
great! it worked!! we declared it as global variable right? and I have so many more (atleast 10 cmd buttons which has some values to be returned) cmd buttons similarly which I want to pass data to cmd_submit, So for that I need 10 separate variables to be declared globally? kindly suggest, if any other better idea. thanks!
 
Upvote 0
we declared it as global variable right?
Not quite. The variable is only available to code in that module. To make it Global you would need to replace Dim with Public & it would need to be in a standard module, rather than a userform module.


So for that I need 10 separate variables to be declared globally
Depends on what the variables are & what they're doing.
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,830
Messages
6,181,227
Members
453,025
Latest member
Hannah_Pham93

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