Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

macros

ResolvedVersion 365

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

Thu 25 Apr 2024: Automatically marked as resolved.

 

Training courses

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Excel tip:

Reset Excel toolbars to default settings

If you find any of your toolbars in Excel have changed (i.e. they are missing or have extra buttons) then you can reset them to their defaults.

1. Go to Tools - Customise.
2. Select the Toolbars tab.
3. Select (highlight) the name of the toolbar you wish to reset, then click the Reset button on the right.
4. Close the dialogue box.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.1 secs.