macros

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

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

Macros

resolvedResolved · Low Priority · Version 2007

Sejal has attended:
Excel Advanced course

Macros

How to use a Macros with Vlookup formulas, and to link multiply spreadsheet.

RE: Macros

Hi Sejal, thanks for your query. To use the VLOOKUP function in a macro you need to call up the macro with the following code:

Dim Answer As [Type] (Select the type to correspond to the type of value being returned)

Answer = Application.WorksheetFunction.VLookup(Arg1, Arg2, Arg3, [Arg4])

The arguments are the same as when running the VLOOKUP function in the worksheet

The WorksheetFunction command allows you to access all the functions found in Excel's Insert Function dialog box

Hope this helps,

Anthony


 

Excel tip:

Use RANDBETWEEN to generate random numbers

There may be occassions where you need to generate random numbers in your spreadsheet. Use the RANDBETWEEN function to generate random numbers between two values that you specify.

The function looks like this:

=randbetween(LOW,HIGH)

where LOW is the lowest number you want generated; and HIGH is the highest number you want generated.

This formula will work with both positive and negative LOWs and HIGHs. Also it will only generate integer numbers unless forced to do otherwise by the following:

=randbetween(LOW*10^PRECISION,
HIGH*10^PRECISION)/(10^PRECISION).

where PRECISION represents the levels of decimal precision needed (i.e. if you need numbers with one decimal place, PRECISION would be 1; 2 for two decimal places and so on).

One final note, if the RANDBETWEEN formula does not work in your spreadsheet or returns a "#NAME" error, you need to install the Analysis Toolpak Add-In. You will need to press F2 then Enter following the installation.

View all Excel hints and tips


Server loaded in 0.08 secs.