Ehudz
Ehudz

Reputation: 633

Initializing a UserForm and Loading Variables with VBA in Excel

I have a userform with an initialize event as follows:

Public CurrSpanNum, CurrSegNum As Integer
Private Sub UserForm_Initialize()

        CurrSegNum = Sheets("UserData").Range("C2").value
        Debug.Print "SegForm, SpanNum = " & CurrSpanNum
        CurrSpanNum = Sheets("UserData").Range("D2").value
        Debug.Print "SegForm, SegNum = " & CurrSegNum

End Sub

In the immediate window I see:

SegForm, SpanNum = 
SegForm, SegNum = 3

The value 3 is placed in both cells before the form is initialized. Why can't I seem to load SpanNum while SegNum is able to load?

Upvotes: 0

Views: 10479

Answers (1)

panda-34
panda-34

Reputation: 4209

Well, your CurrSpanNum variable is not initialized and so prints nothing, What would you expect?

Upvotes: 4

Related Questions