Loop a formula to populate multiple TextBoxes on UserForm

Lectricman

New Member
Joined
Feb 18, 2016
Messages
14
Can anyone help with what I thought would be an easy job?
I would like to populate 13 TextBoxes (101 to 113) with data held in a range of cells.
The following formula does the trick on a single box, but I'm going to end up with maybe 100 or more boxes to do.
Code:
TextBox101.Text = Application.WorksheetFunction.Text(ThisWorkbook.Sheets("Calcs").Range("B15").Value, "[h]:mm")

The data is held in a single row: (B15:N15).
Many thanks for any help.
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
TRy
Code:
    For i = 1 To 13
    Controls("TextBox10" & i).Text = Application.WorksheetFunction.Text(ThisWorkbook.Sheets("Calcs").Cells(15, i + 1).Value, "[h]:mm")
    Next i
 
Upvote 0
TRy
Code:
    For i = 1 To 13
    Controls("TextBox10" & i).Text = Application.WorksheetFunction.Text(ThisWorkbook.Sheets("Calcs").Cells(15, i + 1).Value, "[h]:mm")
    Next i
I think you need to change your code as follows (your concatenations will have a problem when "i" reaches 10)...
Code:
[table="width: 500"]
[tr]
	[td]For i = 101 To 113
  Controls("TextBox" & i).Text = Application.WorksheetFunction.Text(ThisWorkbook.Sheets("Calcs").Cells(15, i + 1).Value, "[h]:mm")
Next i[/td]
[/tr]
[/table]
 
Last edited:
Upvote 0
Good point Rick.
Serves me right for testing on only 3 txtboxes & not thinking!
Code:
For i = 101 To 113
  Controls("TextBox" & i).Text = Application.WorksheetFunction.Text(ThisWorkbook.Sheets("Calcs").Cells(15, i -99).Value, "[h]:mm")
Next i
Although the Cells needs to be changed as well
 
Last edited:
Upvote 0
Good point Rick.
Serves me right for testing on only 3 txtboxes & not thinking!
Code:
For i = 101 To 113
  Controls("TextBox" & i).Text = Application.WorksheetFunction.Text(ThisWorkbook.Sheets("Calcs").Cells(15, i -99).Value, "[h]:mm")
Next i
Although the Cells needs to be changed as well
Good point Fluff.
Serves me right for not looking at the entire code line. :lol:
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,988
Members
452,373
Latest member
TimReeks

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