Write value to a textbox in Userform - VBA

I am trying to write a value dynamically in Textbox which is placed on a Userform. This is my code, and I am getting an error in the last line. It says object required.

Sub Userform1_Display()

TotalSelected = 0

With Sheets("Main").Ent_ListBox

    For i = 0 To .ListCount - 1
        If .Selected(i) = True Then
          Count = 1
          TotalSelected = TotalSelected + Count
        End If
    Next i

End With

'Useform'
Questionaire.Show

'TextBox placed in Userform'
N_Ent_TextBox.Value = TotalSelected


End Sub

Kindly share your thoughts

Upvotes: 2

Views: 6195

Answers (2)

SierraOscar
SierraOscar

Reputation: 17647

It looks like your code isn't actually inside the userform's class module - so you need to fully qualify the object:

Questionaire.N_Ent_TextBox.Value = TotalSelected

Upvotes: 3

Fahad Ejaz Butt
Fahad Ejaz Butt

Reputation: 113

N_Ent_TextBox.Text = TotalSelected try to use this

Upvotes: -1

Related Questions