简体   繁体   中英

Update multiple text boxes in an Excel userform with data from variables

I am looking for a way to update multiple text boxes in an Excel userform with data from a variable array. The text boxes are named as TextBox1, TextBox2 etc. And I want to update these text boxes in a DO LOOP rather than updating each text box line by line.

The variable array will contain n values for the n text boxes in the user form.

I am quite new to the user forms; Any help is appreciated.

Thanks.

Try and customize this to fit your needs:

' Declare variables
Dim arrValues As Variant
Dim counter As Integer

' Initialize array
arrValues = Array("a", "b", "c")

' Loop through array items
For counter = 0 To UBound(arrValues)

    ' Refer to textboxes names from controls collections and assign array values
    Me.Controls("TextBox" & counter + 1).Text = arrValues(counter)

Next counter

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM