Populating userform text boxes

llan_man

New Member
Joined
Nov 6, 2005
Messages
45
Hi

I have the following code which puts default values into some textboxes in a userform. I have repeated this code several times within my project. As you can see the text box names change from p1 through to p12. I have tried using a for next loop from 1 to 12 to try to make my code more efficient but not exactly sure how to do this.

Thanks

Harv


Code:
RevPhasing.p1phase0405.Text = FormatPercent(Val(Sheets("Revenue").Range("e12")), 1)
RevPhasing.p2phase0405.Text = FormatPercent(Val(Sheets("Revenue").Range("f12")), 1)
RevPhasing.p3phase0405.Text = FormatPercent(Val(Sheets("Revenue").Range("g12")), 1)
RevPhasing.p4phase0405.Text = FormatPercent(Val(Sheets("Revenue").Range("h12")), 1)
RevPhasing.p5phase0405.Text = FormatPercent(Val(Sheets("Revenue").Range("i12")), 1)
RevPhasing.p6phase0405.Text = FormatPercent(Val(Sheets("Revenue").Range("j12")), 1)
RevPhasing.p7phase0405.Text = FormatPercent(Val(Sheets("Revenue").Range("k12")), 1)
RevPhasing.p8phase0405.Text = FormatPercent(Val(Sheets("Revenue").Range("l12")), 1)
RevPhasing.p9phase0405.Text = FormatPercent(Val(Sheets("Revenue").Range("m12")), 1)
RevPhasing.p10phase0405.Text = FormatPercent(Val(Sheets("Revenue").Range("n12")), 1)
RevPhasing.p11phase0405.Text = FormatPercent(Val(Sheets("Revenue").Range("o12")), 1)
RevPhasing.p12phase0405.Text = FormatPercent(Val(Sheets("Revenue").Range("p12")), 1)
RevPhasing.totalphase0405.Text = FormatPercent(Val(Sheets("Revenue").Range("r12")), 1)
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Try this.
Code:
For I = 1 to 12
     RevPhasing.Controls("p" & i & "phase0405".Text = FormatPercent(Val(Sheets("Revenue").Cells(12, i+4), 1) 
Next I

RevPhasing.totalphase0405.Text = FormatPercent(Val(Sheets("Revenue").Range("r12")), 1)
 
Upvote 0

Forum statistics

Threads
1,214,989
Messages
6,122,622
Members
449,093
Latest member
catterz66

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