Deceleration of variable in VBA

What is Variable?
A Variable is a name given by users to assign a piece of data that is stored inside computer’s memory.Variables hold values of different data types that are specified when the variable is declared. Deceleration of variable includes four keywords in a particular order:
1. The Dim statement (VBA’s abbreviation for “Dimension”)
2. The name of your variable, which you create, such as vals_name
3. The word As.
4. The type of data being stored.[datatypes]
Dim vals_name As String
Dim vals_name1 as Integer, vals_name2 as Integer, vals_name3 as Integer
Dim vals_name1, vals_name2, vals_name3 as Integer
Assignment is very simple--
vals_name= Application.ActiveWorkbook.Worksheets(“Sheet1”).Range(“A1”).Value
or else
vals_name= Worksheets(“Sheet1”).Range(“A1”).Value  [it automatically assume current application and current Workbook]

Deceleration of variable in VBA Deceleration of variable in VBA Reviewed by Animesh Chatterjee on September 17, 2012 Rating: 5


  1. Hi Animesh da this is Sourav Mukhopadhyay
    Am struck while writing a macro.
    I want to write a code where a column will randomly select values from a give range. (Values are FPO,None, 10% Compound,20% Off)...>Can you please help me out of this.

  2. Hi Sourav,
    take 1st 5 cel values from user
    put this an array
    now take one element from this array
    now do a random no generation (101>number>0)
    take no number in the list
    check the number is in the list

    so when an random value is generated -->it will check the values in the list--> if it not there insert the array element to the random place. do this loop for 20 times.
    So this way you can generate 20*5 =100 test data generated


Powered by Blogger.