How to call a module to a button (1 Viewer)

Fayaz_2020

New member
Local time
Today, 12:00
Joined
Aug 24, 2020
Messages
3
Hi Everyone
I am new to this group and new to VBA also. I just want to know how do I call a Module to a button.
I have Module as below.

Private Sub doublevalues()
Dim r As Long 'row number
Dim totalrows As Long 'total rows

totalrows = Application.CountA(Columns(1))

For r = 2 To totalrows
Cells(r, 1).Value = Cells(r, 1).Value * 2
Next r

End Sub

I want to get the result when I click a button.
How can I do it. Experts please help.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:00
Joined
Oct 29, 2018
Messages
21,454
Hi. Welcome to AWF!

Can you tell us where you placed this Private Sub? Also, if you're using Cells(), is this an Excel question?
 

June7

AWF VIP
Local time
Yesterday, 21:00
Joined
Mar 9, 2014
Messages
5,465
Is this an ActiveX button on Excel worksheet?

Call procedure in button Click event

Private Sub btnTest_Click()
Call doublevalues
End Sub

Or put the complete code within Click event.
 

Fayaz_2020

New member
Local time
Today, 12:00
Joined
Aug 24, 2020
Messages
3
Is this an ActiveX button on Excel worksheet?

Call procedure in button Click event

Private Sub btnTest_Click()
Call doublevalues
End Sub

Or put the complete code within Click event.
yes this is activex button
 

Fayaz_2020

New member
Local time
Today, 12:00
Joined
Aug 24, 2020
Messages
3
Hi. Welcome to AWF!

Can you tell us where you placed this Private Sub? Also, if you're using Cells(), is this an Excel question?
I have placed private sub in Module. Yes this is Excel VBA question.
 

Isaac

Lifelong Learner
Local time
Yesterday, 22:00
Joined
Mar 14, 2017
Messages
8,774
Right click on the button, then click on assign macro, then click on and select the macro you want to assign to the button.

a module is a large container holding many lines of code and presumably multiple procedures. You do not assign a module to anything. You assign a procedure to something


Testing 20200824.jpg
 
Last edited:

Users who are viewing this thread

Top Bottom