Userform Textbox's Multiples - Easier way to get cell data to these boxes

Dingoz2012

Board Regular
Joined
Jan 29, 2012
Messages
163
Hi.

Would appreciate any help.

I have a userform with 100 Textboxes on it. The majority of the textboxes will be for the DISPLAY of cell values only. With some being used for the input of new data which the goes onto the worksheet.

My question is. Is there an easier way to get the cell data into the textboxes, than what is currently being done, which is the below.

Code:
'Required Number of Components
'These go from textbox1 to 14   Cell range b9 to b22

Textbox1.value = sheets("Data").range("b9").value 
Textbox2.value = sheets("Data").range("b10").value

' Already Built
' These go from textbox15 to textbox28 cells c9 to c22

Textbox15.value = sheets("Data").range("c9").value
textbox16.value =sheets("Data").range("c10").value 


' Etc Etc, multiple columns, with groupings of data primarily in range B9 to B22, C9 to C22, E9 to E22 etc etc


Any help greatly appreciated.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Hi,
untested but you can try

Code:
    Dim TextBoxData As Variant
    Dim i As Integer, r As Integer, c As Integer


    TextBoxData = ThisWorkbook.Worksheets("Data").Cells(9, 2).Resize(14, 7).Value2


    For c = 1 To UBound(TextBoxData, 2)
        For r = 1 To UBound(TextBoxData, 1)
            i = i + 1
            Me.Controls("TextBox" & i).Value = TextBoxData(r, c)
        Next r
    Next c

Dave
 
Upvote 0
Hi,
untested but you can try

Code:
    Dim TextBoxData As Variant
    Dim i As Integer, r As Integer, c As Integer


    TextBoxData = ThisWorkbook.Worksheets("Data").Cells(9, 2).Resize(14, 7).Value2


    For c = 1 To UBound(TextBoxData, 2)
        For r = 1 To UBound(TextBoxData, 1)
            i = i + 1
            Me.Controls("TextBox" & i).Value = TextBoxData(r, c)
        Next r
    Next c

Dave


Thank you so much. It work exactly how I was after.
 
Upvote 0
Most welcome - thanks for feedback

Dave
 
Upvote 0
No worries, I greatly value the suggestions by people on here. I go away and dissect the code to see if I can figure out how it works. I'm now onto the second part of my problem. Been struggling for a few hours trying to figure out the most efficient way of getting new data back to the sheet.

So that above code populates the boxes that are on the user form. Is there a way of if I change a value in any of those textboxes that it can be sent to the worksheet in the corresponding cell. ? Without having to type out a line like sheets("Data").range("G9").value = me.textbox71.value etc etc for a 100 textboxes.. :)

Nothing like a challenge
 
Last edited:
Upvote 0
Hi,
just use same approach but in reverse

Code:
    Dim i As Integer, r As Integer, c As Integer
    
    Dim TextBoxData(1 To 14, 1 To 7) As Variant


    For c = 1 To UBound(TextBoxData, 2)
        For r = 1 To UBound(TextBoxData, 1)
            i = i + 1
             TextBoxData(r, c) = Me.Controls("TextBox" & i).Value
        Next r
    Next c
    
    ThisWorkbook.Worksheets("Data").Cells(9, 2).Resize(14, 7).Value = TextBoxData

Dave
 
Upvote 0
Hi,
just use same approach but in reverse

Code:
    Dim i As Integer, r As Integer, c As Integer
    
    Dim TextBoxData(1 To 14, 1 To 7) As Variant


    For c = 1 To UBound(TextBoxData, 2)
        For r = 1 To UBound(TextBoxData, 1)
            i = i + 1
             TextBoxData(r, c) = Me.Controls("TextBox" & i).Value
        Next r
    Next c
    
    ThisWorkbook.Worksheets("Data").Cells(9, 2).Resize(14, 7).Value = TextBoxData

Dave

Of course, why didn't I think of this. hahahahaha.

It kind of works but then it doesn't at the same time.

The original one works, to get the data into the text boxes from column 2 row 9-22 through to column 17 rows 9-22. But when I use the second one to add data back to the sheet I only need to add data back to the range of cells g9:q22 I'm stuck on how to get that working, because at the moment it's only changing the values in 2 columns
 
Upvote 0
If you want to post data to another range then amend code as follows

Rich (BB code):
ThisWorkbook.Worksheets("Data").Cells(9, 7).Resize(14, 7).Value = TextBoxData

Dave
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,178
Members
452,615
Latest member
bogeys2birdies

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top