How do you use a Variable In CheckBox name?

Bebbster

New Member
Joined
Feb 2, 2011
Messages
2
Hello All,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
I have been using this fantastic forum for many months now without having to post, a big thanks you to you all!:biggrin:<o:p></o:p>
This is my first so I apologise if I haven't posted quite right. Please point me in the right direction!<o:p></o:p>

Excel 2007 VBA
<o:p></o:p>
Please can anyone help with the below?:confused:<?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /><v:shapetype id=_x0000_t75 stroked="f" filled="f" path="m@4@5l@4@11@9@11@9@5xe" o:preferrelative="t" o:spt="75" coordsize="21600,21600"> <v:stroke joinstyle="miter"></v:stroke><v:formulas><v:f eqn="if lineDrawn pixelLineWidth 0"></v:f><v:f eqn="sum @0 1 0"></v:f><v:f eqn="sum 0 0 @1"></v:f><v:f eqn="prod @2 1 2"></v:f><v:f eqn="prod @3 21600 pixelWidth"></v:f><v:f eqn="prod @3 21600 pixelHeight"></v:f><v:f eqn="sum @0 0 1"></v:f><v:f eqn="prod @6 1 2"></v:f><v:f eqn="prod @7 21600 pixelWidth"></v:f><v:f eqn="sum @8 21600 0"></v:f><v:f eqn="prod @7 21600 pixelHeight"></v:f><v:f eqn="sum @10 21600 0"></v:f></v:formulas><v:path o:connecttype="rect" gradientshapeok="t" o:extrusionok="f"></v:path><o:lock aspectratio="t" v:ext="edit"></o:lock></v:shapetype><v:shape id=Picture_x0020_1 style="VISIBILITY: visible; WIDTH: 12pt; HEIGHT: 15.75pt; mso-wrap-style: square" alt="0" type="#_x0000_t75" o:spid="_x0000_i1025"><v:imagedata o:title="0" src="file:///C:\DOCUME~1\JASON~1.BEB\LOCALS~1\Temp\msohtmlclip1\01\clip_image001.gif"></v:imagedata></v:shape><o:p></o:p>
<o:p></o:p>
The below piece of code Sub RPCSUpdateCategories() is for updating 40 CheckBox Captions on a userfrm from the sheet RPCSSystemsUse Range("B16:B55").<o:p></o:p>
I have only included a few to save space on the board.<o:p></o:p>
<o:p></o:p>
"Sub RPCSUpdateCategories()<o:p></o:p>
<o:p></o:p>
'RPCS Summary Categories
IPPMainFRM.CheckBox1.Caption = Worksheets("RPCSSystemsUSE").Range("B16").Value
IPPMainFRM.CheckBox2.Caption = Worksheets("RPCSSystemsUSE").Range("B17").Value
IPPMainFRM.CheckBox3.Caption = Worksheets("RPCSSystemsUSE").Range("B18").Value
IPPMainFRM.CheckBox4.Caption = Worksheets("RPCSSystemsUSE").Range("B19").Value
IPPMainFRM.Repaint<o:p></o:p>

End Sub"<o:p></o:p>
<o:p></o:p>
What I am trying to achieve is the above but without 40 lines of repeated code.<o:p></o:p>
<o:p></o:p>
The below code won't work because I can't figure out how to make the CheckBox include a variable as part of its name? <o:p></o:p>
<o:p></o:p>
RPCSCheckBoxesName would be CheckBox1 to 40 if its not a variable.<o:p></o:p>
<o:p></o:p>
"Sub Testcheckboxes()<o:p></o:p>

Dim RPCSCategoryRange As Long
Dim RPCSCheckBoxesNo As Long
Dim
RPCSCheckBoxesName As String<o:p></o:p>
<o:p></o:p>
RPCSCategoryRange = 16
For RPCSCheckBoxesNo = 1 To 40<o:p></o:p>


RPCSCategoryRange = RPCSCategoryRange + 1<o:p></o:p>

RPCSCheckBoxesName = "CheckBox" & RPCSCheckBoxesNo<o:p></o:p>

If Range("B" & RPCSCategoryRange).Value = "" Then<o:p></o:p>

Else<o:p></o:p>
IPPMainFRM.RPCSCheckBoxesName.Caption = Worksheets("RPCSSystemsUSE").Range("B" & RPCSCategoryRange).Value
IPPMainFRM.Repaint
End If<o:p></o:p>

<o:p></o:p>
Next RPCSCheckBoxesNo<o:p></o:p>
<o:p></o:p>
End Sub"<o:p></o:p>
<o:p></o:p>
Any help would be greatly appreciated,<o:p></o:p>
<o:p> </o:p>
Thanks,<o:p></o:p>
<o:p> </o:p>
Jase <o:p></o:p>
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Close!
Replace:
IPPMainFRM.RPCSCheckBoxesName.Caption
with:
IPPMainFRM.Controls(RPCSCheckBoxesName).Caption
 
Upvote 0

Forum statistics

Threads
1,224,531
Messages
6,179,384
Members
452,908
Latest member
MTDelphis

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