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)
 

Some videos you may like

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,047
Office Version
  1. 365
Platform
  1. Windows
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)
 

Watch MrExcel Video

Forum statistics

Threads
1,118,081
Messages
5,570,088
Members
412,310
Latest member
mark884
Top