Emma-louise has attended:
Excel Intermediate course
Excel Advanced course
Macros
Hi,
I am looking at a macro i did not write and trying to understand what the different modules mean i.e. Module 1-4 do they run in the order i see them,
Is it possible to rename them?
Also what does this mean
Dim Wk1 As Worksheet
RE: Macros
Hello Emma-Louise,
Thank you for your question.
When you’re dealing with Excel macros and their modules, it’s essential to understand the order in which they execute. A module is like a folder which contains code. Let me break it down for you:
In Excel VBA (the code language), the order of execution for modules is only sequential if this is coded in, e.g.
Call Module1
Call Module2
Call Module3, etc.
(or if the module name is simply referenced in the code)
If sequential running is not coded in, modules behave on a stand-alone basis which means you need to run them manually.
You can rename modules in the Name field of the Properties window in Excel's Visual Basic Editing window (Alt + F11) > View > Properties Window.
The line 'Dim Wk1 As Worksheet' declares a variable named Wk1 of the type 'Worksheet'. Let me explain further:
Dim: This keyword stands for “dimension” and is used to declare variables in VBA. It indicates that we are creating a new variable.
Wk1: This is the name of the variable being declared. You can choose any valid variable name you like (within certain rules), but it’s a good practice to use descriptive names.
As Worksheet: This part specifies the data type of the variable. In this case, we are declaring Wk1 as a Worksheet object.
In summary, this line of code creates a variable named Wk1 that can hold a reference to a worksheet within an Excel workbook. You can then use this variable to manipulate the worksheet programmatically, such as accessing its cells, properties, or methods (actions).
If you have any more questions or need further clarification, please feel free to ask.
I hope this helps.
Kind regards
Marius Barnard
STL