Av8tordude

Well-known Member
Joined
Oct 13, 2007
Messages
1,074
Office Version
  1. 2019
Platform
  1. Windows
I have userform that has 42 Textboxes and 42 Labels. How can I write a better code...

Code:
Label1 = Format(Range("B4"), "d")
Label2 = Format(Range("C4"), "d")
Label3 = Format(Range("D4"), "d")
Label4 = Format(Range("E4"), "d")
Label5 = Format(Range("F4"), "d")
Label6 = Format(Range("G4"), "d")
Label7 = Format(Range("H4"), "d")


Label8 = Format(Range("B6"), "d")
Label9 = Format(Range("C6"), "d")
Label10 = Format(Range("D6"), "d")
Label11 = Format(Range("E6"), "d")
Label12 = Format(Range("F6"), "d")
Label13 = Format(Range("G6"), "d")
Label14 = Format(Range("H6"), "d")


Label15 = Format(Range("B8"), "d")
Label16 = Format(Range("C8"), "d")
Label17 = Format(Range("D8"), "d")
Label18 = Format(Range("E8"), "d")
Label19 = Format(Range("F8"), "d")
Label20 = Format(Range("G8"), "d")
Label21 = Format(Range("H8"), "d")


Label22 = Format(Range("B10"), "d")
Label23 = Format(Range("C10"), "d")
Label24 = Format(Range("D10"), "d")
Label25 = Format(Range("E10"), "d")
Label26 = Format(Range("F10"), "d")
Label27 = Format(Range("G10"), "d")
Label28 = Format(Range("H10"), "d")


Label29 = Format(Range("B12"), "d")
Label30 = Format(Range("C12"), "d")
Label31 = Format(Range("D12"), "d")
Label32 = Format(Range("E12"), "d")
Label33 = Format(Range("F12"), "d")
Label34 = Format(Range("G12"), "d")
Label35 = Format(Range("H12"), "d")


Label36 = Format(Range("B14"), "d")
Label37 = Format(Range("C14"), "d")
Label38 = Format(Range("D14"), "d")
Label39 = Format(Range("E14"), "d")
Label40 = Format(Range("F14"), "d")
Label41 = Format(Range("G14"), "d")
Label42 = Format(Range("H14"), "d")


TextBox1 = Range("B5")
TextBox2 = Range("C5")
TextBox3 = Range("D5")
TextBox4 = Range("E5")
TextBox5 = Range("F5")
TextBox6 = Range("G5")
TextBox7 = Range("H5")


TextBox8 = Range("B7")
TextBox9 = Range("C7")
TextBox10 = Range("D7")
TextBox11 = Range("E7")
TextBox12 = Range("F7")
TextBox13 = Range("G7")
TextBox14 = Range("H7")


TextBox15 = Range("B9")
TextBox16 = Range("C9")
TextBox17 = Range("D9")
TextBox18 = Range("E9")
TextBox19 = Range("F9")
TextBox20 = Range("G9")
TextBox21 = Range("H9")


TextBox22 = Range("B11")
TextBox23 = Range("C11")
TextBox24 = Range("D11")
TextBox25 = Range("E11")
TextBox26 = Range("F11")
TextBox27 = Range("G11")
TextBox28 = Range("H11")


TextBox29 = Range("B13")
TextBox30 = Range("C13")
TextBox31 = Range("D13")
TextBox32 = Range("E13")
TextBox33 = Range("F13")
TextBox34 = Range("G13")
TextBox35 = Range("H13")


TextBox36 = Range("B15")
TextBox37 = Range("C15")
TextBox38 = Range("D15")
TextBox39 = Range("E15")
TextBox40 = Range("F15")
TextBox41 = Range("G15")
TextBox42 = Range("H15")
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
How about
Code:
   Dim i As Long, j As Long, k As Long
   For i = 4 To 14 Step 2
      For j = 2 To 8
         k = k + 1
         Me.Controls("Label" & k) = Format(Cells(i, j), "d")
         Me.Controls("textbox" & k) = Cells(i + 1, j)
      Next j
   Next i
 
Upvote 0

Forum statistics

Threads
1,214,400
Messages
6,119,292
Members
448,885
Latest member
LokiSonic

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