mutluilker
mutluilker

Reputation: 23

What is the meaning of two dot in this code?

I want to learn what is usage of two dot in excel vba.

Sub loadparts(a)    
    Sheets("Sheet1").Select

    Dim lists()    
    b = 2    
    'what is the meaning of two dots.

x:
    If Cells(b, a) <> "" Then   
        ReDim Preserve lists(1 To b - 1)   
        lists(b - 1) = Sheets(b, a)

        b = b - 1: GoTo x
    End If

    UserForm1.ListBox1.List = lists()  
End Sub

Upvotes: 1

Views: 3425

Answers (2)

steenbergh
steenbergh

Reputation: 1761

The two dots are called a colon. And the colon has two functions in Visual Basic for Applications

Defining a label: In your example x is a label. You can use labels to jump to a specific part of your code, with the goto statement. In your example, this happens on this line:

b = b - 1: GoTo x

And you can use it to separate instructions (which incidentally happens on the same line). In VBA we usually separate statements with newlines, but one could also use the colon. Though this usually doesn't read too easily. Grabbing the same line of code again:

b = b - 1: GoTo x

is equivalent to

b = b - 1
GoTo x

Upvotes: 5

artemis
artemis

Reputation: 7241

In this, the 'two dots', or the colon, is a delimiter of statements. It is a shorthand way of writing multiple lines of VBA code, in one line. For example...

b = b - 1: GoTo x

is equivalent to

b = b - 1

GoTo x

Excel VBA Pound and Colon Signs Meaning?

Upvotes: 2

Related Questions