Resources on VBA Excel @ ExcelOptimize.Com
Currently Browsing: VBA Excel

Loading Add-ins Automatically

Loading Add-ins Automatically
This tips will give you steps on how to selectively load add-ins in specific worksheet, we’re able to do this on with a little code on macro. Here’s the steps: Activate the worksheet in which you want an add-in to be loaded. Press the shortcut button  Alt+F11 to display the VBA Editor or...

Do-Until loop

Do-Until loop
The Do-Until loop structure is similar to the Do-While structure. The two structures differ in their handling of the tested condition. A program continues to execute a Do-While loop while the condition remains true. In a Do-Until loop, the program executes the loop until the condition is true. Here’s...

Do-While loop

Do-While loop
VBA supports another type of looping structure known as a Do-While loop. Unlike a For-Next loop, a Do-While loop continues until a specified condition is met. Here’s the Do-While loop syntax: Do [While condition] [statements] [Exit Do] [statements] Loop The following example uses a Do-While loop....

Nested For-Next

Nested For-Next
So far, all this chapter’s examples use relatively simple loops. However, you can have any number of statements in the loop and nest For-Next loops inside other For-Next loops. The following example uses a nested For-Next loop to insert random numbers into a 12-row-x-5-column range of cells, as shown...

For-Next with an Exit For statement

For-Next with an Exit For statement
A For-Next loop can also include one or more Exit For statements within the loop. When VBA encounters this statement, the loop terminates immediately. The following example, available on the book’s Web site, demonstrates the Exit For statement. This routine identifies which of the active worksheet’s...

For-Next with a Step

For-Next with a Step
You can use a Step value to skip some values in a For-Next loop. Here’s the same procedure as in the preceding section, rewritten to insert random numbers into every other cell: Sub FillRange() Dim Count As Long For Count = 1 To 100 Step 2 ActiveCell.Offset(Count – 1, 0) = Rnd Next Count End...

For-Next loops

For-Next loops
The simplest type of loop is a For-Next loop. Here’s the syntax for this structure: For counter = start To end [Step stepval] [statements] [Exit For] [statements] Next [counter] The looping is controlled by a counter variable, which starts at one value and stops at another value. The statements between...

Looping Code

Looping Code
The term looping refers to repeating a block of VBA statements numerous times. You may know how many times your program needs to loop, or variables used in your program’s code may determine this. There are two types of loops: good loops and bad loops. (Good loops get rewarded, and bad loops get sent...

Saving Workbooks that Contain Macros

Saving Workbooks that Contain Macros
If you store one or more macros in a workbook, the file must be saved with “macros enabled.” In other words, the file must be saved with an XLSM extension rather than the normal XLSX extension.For example, if you try to save the workbook that contains your NameAndTime macro, the file format in the...

Turning off screen updating

Turning off screen updating
When executing a macro, you can sit back and watch all the on-screen action that occurs in the macro. Although doing this can be instructive, after getting the macro working properly, it’s often annoying and can slow down the course of your macro considerably. Fortunately, you can disable the screen...
 Page 1 of 3  1  2  3 »