Why Modules?

rahulbassi

Board Regular
Joined
Aug 14, 2011
Messages
130
Hi Everyone,
I've created a tool with the help of Excel and VBA.
It is working fine. I've done the coding the Sheet and forms section. But I've not used any Module.
Definitely, me code is a mess....but working fine...
Please explain me with an example why and where do we use Modules....??
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Thanks for guiding....
Gone through the link too....
still need some more clarification....
Suppose I want a piece of code to run one the click of a command button. Then should i write the code in module or in the form window which opens when I click the button twice in DESIGN MODE..?
If I need to write it in module say Module1.
Then how do I link that code to click event?
 
Upvote 0
Actually I think I've been writing the code in Userform Modules......But i want to know about the usage of Regular modules...
 
Upvote 0
The code for a command button should go in its userform code module.

A regular module would be use for code like this

Code:
Sub test()
Dim i As Long
For i = 1000 To 2 Step -1
    If Range("A" & i).Value = Range("A" & i - 1).Value Then Rows(i).Delete
Next i
End Sub
 
Upvote 0
All userform codes go in the userform module, as in the one that open when you click the command button. All other macros are stored in your regular modules.

Lets say you have a userform. Now the code associated with this userform will be entered in the userform module. But when you want to call the userform through a macro, that macro will be in your regular module.

The best thing would be to spend about an hour and go through the gazillion videos explaining the basics of vba on youtube.
 
Upvote 0
Thanks for explaining......I think I'm getting the things now......will surely follow the videos for coding in VBA.....afterall the quality of code too matters.......
 
Upvote 0

Forum statistics

Threads
1,214,960
Messages
6,122,479
Members
449,088
Latest member
Melvetica

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