• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Some help to make 2 codes shorter

Belleke

Well-Known Member
I have this piece of code when I click an option button
Code:
If OPB_01 Then [F10] = "R"
    If OPB_01 Then [H10] = ""
    If OPB_02 Then [H10] = "S"
    If OPB_02 Then [F10] = ""
R & S is because the cells are formated as Windings2
this works perfect. but
OPB_.. are option buttons, and I have 48 option buttons
Can this code shorter?
And the second question to make code shorter
I have this code to fill textboxes when I click in a listbox
Code:
T_02.Value = LB_03.Column(1)
T_03.Value = LB_03.Column(2)
T_04.Value = LB_03.Column(3)
T_05.Value = LB_03.Column(4)
etc.
(T_... are textboxes)
Same question
Please advice if it is possible.
Thanks
 
Hi, Belleke!
Code:
If OPB_01 Then [F10] = "R"
    If OPB_01 Then [H10] = ""
    If OPB_02 Then [H10] = "S"
    If OPB_02 Then [F10] = ""
This can be reduce to the half+1:
Code:
Private Sub x()
    [F10,H10] = ""
    If OPB_01 Then [F10] = "R"
    If OPB_02 Then [H10] = "S"
End SuB
Code:
T_02.Value = LB_03.Column(1)
T_03.Value = LB_03.Column(2)
T_04.Value = LB_03.Column(3)
T_05.Value = LB_03.Column(4)
If controls are ActiveX you can try this (doesn't work for Forms controls):
Code:
Private Sub y()
    Dim ctl As Control
    Dim I As Integer, J As Integer, A As String, B As String
    For I = 1 To ActiveSheet.OLEObjects.Count
        If Left(ActiveSheet.OLEObjects(I).Name, 3) = "TB_" Then
            B = Right(ActiveSheet.OLEObjects(I).Name, 2)
            J = Val(B)
            ActiveSheet.OLEObjects("TB_" & B).Object.Value = Range("LB_03").Cells(1, J + 1)
        End If
    Next I
End Sub
Hope it helps.
Regards!
 

Attachments

  • Some help to make 2 codes shorter (for Belleke at Chandoo.org).xlsm
    23.6 KB · Views: 4
Hi, Belleke!
Glad you solved it. Thanks for your feedback and welcome back whenever needed or wanted.
Regards!
 
Back
Top