[Solved] Static Range within VB script

Hello,

Is it possible to define Static Range of certain values inside the VB Script;

Example

Dim Rng as range

Set Rng = [0,10,20,30,40,50,60,70,80,90,100]

Means instead of setting range location from the sheet, giving fix vales

regards,
 
Hello,

Is it possible to define Static Range of certain values inside the VB Script;

Example

Dim Rng as range

Set Rng = [0,10,20,30,40,50,60,70,80,90,100]

Means instead of setting range location from the sheet, giving fix vales

regards,
Hello Mfaisal

Thanks for reaching out and posting your issue. In VBScript, you cannot directly define a static range of values like an array using the range object. The range object in VBScript is typically used to represent a cell or a range of cells in an Excel worksheet.

If you want to create an array with specific values in VBScript, you can use the Array Literal notation to define an array with fixed values.

Code:
Sub Test()
    
    Dim Rng As Variant

    Rng = Array(0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100)

    Debug.Print Rng(1)
    
End Sub

In the code above, an array named Rng is declared with a size of 10. Later, Each element of the array is assigned a specific value. Keep in mind that VBScript arrays are Zero-based. The first element is accessed using an index of 0, the second element with an index of 1, and so on.

I hope this will achieve your goal. Feel free to contact us again with any other inquiries or concerns.

Regards
Lutfor Rahman Shimanto
 

Online statistics

Members online
1
Guests online
39
Total visitors
40

Forum statistics

Threads
303
Messages
1,331
Members
550
Latest member
JasonRip
Top