Trying to learn VBA in Excel context. I'd like to populate a listbox from a range in column A, on Sheet2 (some text strings in the column) as in the following code
Public Sub Test()
Dim NumTags As Integer
Dim TagString As String
NumTags = Worksheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).Row
UserForm1.Show
TagString = "A1:A" & NumTags
'Worksheets("Sheet2").Activate
UserForm1.ListBox1.RowSource = TagString
End Sub
If I call this sub while Sheet1 is activated, it will not populate the listbox properly, or at least not every time. If I uncomment that Worksheets("Sheet2").Activate line, everything works properly, but of course it switches activation to Sheet2, which I don't want.
Question: Why is that? Am I populating the ListBox in some incorrect/shabby way?
Thanks for your help!