macros

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

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Macros

Macros

resolvedResolved · Medium Priority · Version 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

 

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:

Turn off AutoComplete in Excel

You may have noticed when typing into your spreadsheets that if you start to enter labels that begin with the same letters as a label that has been previously entered in the same spreadsheet, Excel will try and automatically complete the text for you. This feature is called AutoComplete.

If you find this feature more annoying than useful, you can turn it off by:

1. Going to Tools - Options.

2. Select the Edit tab.

3. Remove the tick from next to the "Enable AutoComplete for cell values" option.

4. Click OK.

View all Excel hints and tips


Server loaded in 0.08 secs.