Pass value from multiple textboxes on userform to cells in worksheet

Jimmypop

Well-known Member
Joined
Sep 12, 2013
Messages
753
Office Version
  1. 365
Platform
  1. Windows
Good day again people need some assistance again

I realize and can do one or two textboxes with code that I have done before but my issues (which I hope can be fixed and is not too difficult) is as follows: (bit of a challenge for you:p:ROFLMAO::ROFLMAO:):

  • I have 468 Textboxes on a userform (named Percentages). I want to that when value in textbox is updated it is passed onto a certain cell on the worksheet namely:

    VBA Code:
    Textbox1.Value to cell B2
    Textbox2.Value to cell C2
    Textbox3.Value to cell D2
    Textbox4.Value to cell E2
    Textbox5.Value to cell F2
    Textbox6.Value to cell G2
    Textbox7.Value to cell H2
    Textbox8.Value to cell I2
    Textbox9.Value to cell J2
    Textbox10.Value to cell K2
    Textbox11.Value to cell L2
    Textbox12.Value to cell M2

  • So therefore Textbox13 – Textbox24 will be added to B3:M3 etc. (I have added a screenshot of worksheet and userform)

    Range for percentages is B2:M39
 

Attachments

  • Capture.PNG
    Capture.PNG
    85.5 KB · Views: 7

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Try this in the form module.
VBA Code:
Private Sub CommandButton1_Click()
    Dim i As Integer, j As Integer
    For j = 1 To 39 'Row
        For i = 1 To 12 'Column
            Cells(j + 1, i + 1).Value = Me.Controls("TextBox" & (j - 1) * 12 + i).Value
        Next
    Next
End Sub
 
Upvote 0
Hi kanadaaa

It works but with some error at the end on line

VBA Code:
Cells(j + 1, i + 1).Value = Me.Controls("TextBox" & (j - 1) * 12 + i).Value
 

Attachments

  • Untitled.png
    Untitled.png
    101.9 KB · Views: 5
Upvote 0
I think you have some textbox that isn't named TextBox + numeral.
 
Upvote 0
It must be a hassle to go over every textbox so you might want to use this code to figure out which one is causing the error:

VBA Code:
Private Sub CommandButton1_Click()
    Dim i As Integer, j As Integer
    On Error GoTo errHandler
    For j = 1 To 39 'Row
        For i = 1 To 12 'Column
            Cells(j + 1, i + 1).Value = Me.Controls("TextBox" & (j - 1) * 12 + i).Value
        Next
    Next
errHandler:
    Debug.Print i
    Debug.Print j
End Sub
 
Upvote 0
It will be yes ? ? ...

I have updated the code and it is not giving me the error now. Whoooppeee...

But it was not updating the last row of worksheet.... Row 39.. I investigated and realized that the last row of text boxes did not follow in sequence...corrected and working now.

It was quite simple solution.??
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,738
Members
448,988
Latest member
BB_Unlv

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