We help IT Professionals succeed at work.

looping syntax

Hi Experts,

How do I use a loop in VBA for the following
I would like to use the same logic of code for different values
Something like

For MyVar = "A","B","C"
s=MyVar
Next
Comment
Watch Question

If you can use an array for your variable, you could do this....

Dim MyVar, i As Integer
MyVar = Array("A", "B", "C")
For i = 0 To UBound(MyVar)
    MsgBox MyVar(i)
Next

Open in new window

Hi,
What is the difference between array function and split?
Split accepts a single string, so you can't use "A","B","C", but you could use "A,B,C".

The Split function will then return an array, so this....

    MyVar = Array("A", "B", "C")

...will return the same result as this....

    MyVar = Split("A,B,C", ",")

Wayne
Thank You!