+ Reply to Thread
Results 1 to 5 of 5

Assign fixed values to array / For...Next loop

  1. #1
    Forum Contributor
    Join Date
    08-12-2010
    Location
    Excel World
    MS-Off Ver
    Excel 2013, 2019 & O365
    Posts
    214

    Thumbs up Assign fixed values to array / For...Next loop

    Hi All!,

    Can you please help me with below situation?

    I have written some VBA codes and running them for the same kind of activities on some fixed integer values, for example ---> 45, 90, 91, 92, 93, 94, 95, 95, 96, 100.
    I am able to run For...Next loop from 90 to 96, but unable to cover the other numbers like 45 and 100 with it, so I have to write & run the same codes separately for these two. I felt that Array can handle this situation, so tired to google, but not got the success.

    Below are the codes in two methods for example:
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Thanks in advance!
    Last edited by SunOffice; 12-18-2011 at 05:48 PM. Reason: Added anothe method which I applied for above.
    Excelforum is Completely Awesome! True learning with Live Examples & Best Techniques!!

  2. #2
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Assign fixed values to array / For...Next loop

    Please Login or Register  to view this content.



  3. #3
    Forum Contributor
    Join Date
    08-12-2010
    Location
    Excel World
    MS-Off Ver
    Excel 2013, 2019 & O365
    Posts
    214

    Re: Assign fixed values to array / For...Next loop

    Thank You Mr snb!!

    Nice to see you again!

    Please Login or Register  to view this content.
    Just an important question: —»» Do I not need to use below lines? Above is also running without these below lines.
    'Dim iArr(45 To 45, 90 To 96, 100 To 100) As Integer
    'Erase iArr()
    Last edited by SunOffice; 12-18-2011 at 05:32 PM.

  4. #4
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Assign fixed values to array / For...Next loop

    I didn't use an array variable; so there's no need to declare a variable you do not use.

    As long as you refrain from 'Option Explicit' the code I posted suffices.
    Last edited by snb; 12-18-2011 at 05:36 PM.

  5. #5
    Forum Contributor
    Join Date
    08-12-2010
    Location
    Excel World
    MS-Off Ver
    Excel 2013, 2019 & O365
    Posts
    214

    Re: Assign fixed values to array / For...Next loop

    okay.. got it!
    » While using 'Option Explicit', Array is fine in the above case. There is no need to define Dim for iArr
    » If I don't use 'Option Explicit', then I always should define Dim for the array and later Erase that in the last (e.g. - two lines in green color).

    Thank you a ton for explaining it more!!
    Merry Christmas in advance!
    Last edited by SunOffice; 12-18-2011 at 05:48 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1