Creating a For Next Loop

MartyChase

New Member
Joined
Jan 10, 2012
Messages
26
Very new to VB and looking for some help on this basic problem. Thanks in advance.

Trying to convert this code into a For Next Loop:

X = 0
Do Until X = 33
X = X + 1
inst = Choose(X, "ASP", "CAL", "CCC", "CCI", "CCWF", "CEN", "CIM", "CIW", "CMC", "CMF", "COR", "CRC", "CTF", "CVSP", "DVI", "FSP", "HDSP", "ISP", "KVSP", "LAC", "MCSP", "NKSP", "PBSP", "PVSP", "RJD", "SAC", "SATF", "SCC", "SOL", "SQ", "SVSP", "VSPW", "WSP")

Marty
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
With your Column A totally BLANK (no Values) run:

In a Standard Module paste in:
Code:
Sub Foo()
X = 0
Do Until X = 33
X = X + 1
inst = Choose(X, "ASP", "CAL", "CCC", "CCI", "CCWF", "CEN", "CIM", "CIW", "CMC", "CMF", "COR", "CRC", "CTF", "CVSP", "DVI", "FSP", "HDSP", "ISP", "KVSP", "LAC", "MCSP", "NKSP", "PBSP", "PVSP", "RJD", "SAC", "SATF", "SCC", "SOL", "SQ", "SVSP", "VSPW", "WSP")
Cells(X, 1).Value = inst
Loop
End Sub
 
Upvote 0
This is how to construct the loop
Code:
For counter = 1 to 33
    inst = Choose(counter, "ASP", "CAL", "CCC", "CCI", "CCWF", "CEN", "CIM", "CIW", "CMC", "CMF", "COR", "CRC", "CTF", "CVSP", "DVI", "FSP", "HDSP", "ISP", "KVSP", "LAC", "MCSP", "NKSP", "PBSP", "PVSP", "RJD", "SAC", "SATF", "SCC", "SOL", "SQ", "SVSP", "VSPW", "WSP")
Next counter

But all that does is change the value of inst, it would be quicker to do

Code:
inst = inst = Choose(33, "ASP", "CAL", "CCC", "CCI", "CCWF", "CEN", "CIM", "CIW", "CMC", _
    "CMF", "COR", "CRC", "CTF", "CVSP", "DVI", "FSP", "HDSP", "ISP", "KVSP", "LAC", _
    "MCSP", "NKSP", "PBSP", "PVSP", "RJD", "SAC", "SATF", "SCC", "SOL", "SQ", "SVSP", "VSPW", "WSP")


inst = Array("ASP", "CAL", "CCC", "CCI", "CCWF", "CEN", "CIM", "CIW", "CMC", _
    "CMF", "COR", "CRC", "CTF", "CVSP", "DVI", "FSP", "HDSP", "ISP", "KVSP", "LAC", _
    "MCSP", "NKSP", "PBSP", "PVSP", "RJD", "SAC", "SATF", "SCC", "SOL", "SQ", "SVSP", _
    "VSPW", "WSP")(32)
 
Upvote 0

Forum statistics

Threads
1,226,695
Messages
6,192,478
Members
453,727
Latest member
tuong_ng89

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top