❓ Help Yung IT o marunong po sana sa Excel Salamat po need lang

Status
Not open for further replies.

Jorgyy

Established
  • When OptionButton1 is clicked:
    • GroupBox1's option buttons (OptionButton1 to OptionButton5) are unlocked (clickable).
    • GroupBox2's option buttons (OptionButton6 to OptionButton10) are locked (unclickable).
  • When OptionButton2 is clicked:
    • Both GroupBox1 and GroupBox2's option buttons are unlocked (clickable). how to do po in Excel sana mapansin agad if ever kung may format po kayo baka pwede makahingi salamat po :(
 
try mo po to

To achieve the functionality you described in Excel using VBA (Visual Basic for Applications), you'll need to create a UserForm with the option buttons organized into two group boxes. Here's how you can do this step by step:

### Step 1: Create a UserForm
1. Open Excel and press ALT + F11 to open the VBA editor.
2. In the VBA editor, right-click on any of the items for your workbook in the "Project Explorer" on the left side and select Insert > UserForm.
3. Use the Toolbox (if it doesn't appear, select View > Toolbox) to add two Group Boxes and five Option Buttons in each group.

### Step 2: Name Your Controls
  • GroupBox1: GroupBox1
  • OptionButtons in GroupBox1: OptionButton1, OptionButton2, OptionButton3, OptionButton4, OptionButton5
  • GroupBox2: GroupBox2
  • OptionButtons in GroupBox2: OptionButton6, OptionButton7, OptionButton8, OptionButton9, OptionButton10

### Step 3: Add VBA Code
1. Right-click on the UserForm in the Project Explorer and select View Code.
2. In the code window that appears, enter the following code:

Code:
Private Sub OptionButton1_Click()
    ' Unlock GroupBox1 option buttons
    OptionButton1.Enabled = True
    OptionButton2.Enabled = True
    OptionButton3.Enabled = True
    OptionButton4.Enabled = True
    OptionButton5.Enabled = True
    
    ' Lock GroupBox2 option buttons
    OptionButton6.Enabled = False
    OptionButton7.Enabled = False
    OptionButton8.Enabled = False
    OptionButton9.Enabled = False
    OptionButton10.Enabled = False
End Sub

Private Sub OptionButton2_Click()
    ' Unlock both GroupBox1 and GroupBox2 option buttons
    OptionButton1.Enabled = True
    OptionButton2.Enabled = True
    OptionButton3.Enabled = True
    OptionButton4.Enabled = True
    OptionButton5.Enabled = True
    
    OptionButton6.Enabled = True
    OptionButton7.Enabled = True
    OptionButton8.Enabled = True
    OptionButton9.Enabled = True
    OptionButton10.Enabled = True
End Sub

Private Sub OptionButton3_Click()
    ' (Optional: You can add code here if you want any specific behavior)
End Sub

Private Sub OptionButton4_Click()
    ' (Optional: You can add code here if you want any specific behavior)
End Sub

Private Sub OptionButton5_Click()
    ' (Optional: You can add code here if you want any specific behavior)
End Sub

Private Sub OptionButton6_Click()
    ' (Optional: You can add code here if you want any specific behavior)
End Sub

Private Sub OptionButton7_Click()
    ' (Optional: You can add code here if you want any specific behavior)
End Sub

Private Sub OptionButton8_Click()
    ' (Optional: You can add code here if you want any specific behavior)
End Sub

Private Sub OptionButton9_Click()
    ' (Optional: You can add code here if you want any specific behavior)
End Sub

Private Sub OptionButton10_Click()
    ' (Optional: You can add code here if you want any specific behavior)
End Sub

### Step 4: Test the UserForm
1. Close the VBA editor and return to Excel.
2. Open the UserForm you created by pressing F5 in the VBA editor while the UserForm is selected or by adding a button on the worksheet that executes UserForm1.Show (assuming your form is named UserForm1).

### Behavior Explanation
  • Clicking OptionButton1 will unlock OptionButton1 to OptionButton5 in GroupBox1 and lock all buttons in GroupBox2.
  • Clicking OptionButton2 will unlock all buttons in both GroupBox1 and GroupBox2.

You can further customize the behavior of OptionButton3, OptionButton4, and so on by adding specific actions in their respective Click event handlers.
 
try mo po to

To achieve the functionality you described in Excel using VBA (Visual Basic for Applications), you'll need to create a UserForm with the option buttons organized into two group boxes. Here's how you can do this step by step:

### Step 1: Create a UserForm
1. Open Excel and press ALT + F11 to open the VBA editor.
2. In the VBA editor, right-click on any of the items for your workbook in the "Project Explorer" on the left side and select Insert > UserForm.
3. Use the Toolbox (if it doesn't appear, select View > Toolbox) to add two Group Boxes and five Option Buttons in each group.

### Step 2: Name Your Controls
  • GroupBox1: GroupBox1
  • OptionButtons in GroupBox1: OptionButton1, OptionButton2, OptionButton3, OptionButton4, OptionButton5
  • GroupBox2: GroupBox2
  • OptionButtons in GroupBox2: OptionButton6, OptionButton7, OptionButton8, OptionButton9, OptionButton10

### Step 3: Add VBA Code
1. Right-click on the UserForm in the Project Explorer and select View Code.
2. In the code window that appears, enter the following code:

Code:
Private Sub OptionButton1_Click()
    ' Unlock GroupBox1 option buttons
    OptionButton1.Enabled = True
    OptionButton2.Enabled = True
    OptionButton3.Enabled = True
    OptionButton4.Enabled = True
    OptionButton5.Enabled = True
   
    ' Lock GroupBox2 option buttons
    OptionButton6.Enabled = False
    OptionButton7.Enabled = False
    OptionButton8.Enabled = False
    OptionButton9.Enabled = False
    OptionButton10.Enabled = False
End Sub

Private Sub OptionButton2_Click()
    ' Unlock both GroupBox1 and GroupBox2 option buttons
    OptionButton1.Enabled = True
    OptionButton2.Enabled = True
    OptionButton3.Enabled = True
    OptionButton4.Enabled = True
    OptionButton5.Enabled = True
   
    OptionButton6.Enabled = True
    OptionButton7.Enabled = True
    OptionButton8.Enabled = True
    OptionButton9.Enabled = True
    OptionButton10.Enabled = True
End Sub

Private Sub OptionButton3_Click()
    ' (Optional: You can add code here if you want any specific behavior)
End Sub

Private Sub OptionButton4_Click()
    ' (Optional: You can add code here if you want any specific behavior)
End Sub

Private Sub OptionButton5_Click()
    ' (Optional: You can add code here if you want any specific behavior)
End Sub

Private Sub OptionButton6_Click()
    ' (Optional: You can add code here if you want any specific behavior)
End Sub

Private Sub OptionButton7_Click()
    ' (Optional: You can add code here if you want any specific behavior)
End Sub

Private Sub OptionButton8_Click()
    ' (Optional: You can add code here if you want any specific behavior)
End Sub

Private Sub OptionButton9_Click()
    ' (Optional: You can add code here if you want any specific behavior)
End Sub

Private Sub OptionButton10_Click()
    ' (Optional: You can add code here if you want any specific behavior)
End Sub

### Step 4: Test the UserForm
1. Close the VBA editor and return to Excel.
2. Open the UserForm you created by pressing F5 in the VBA editor while the UserForm is selected or by adding a button on the worksheet that executes UserForm1.Show (assuming your form is named UserForm1).

### Behavior Explanation
  • Clicking OptionButton1 will unlock OptionButton1 to OptionButton5 in GroupBox1 and lock all buttons in GroupBox2.
  • Clicking OptionButton2 will unlock all buttons in both GroupBox1 and GroupBox2.

You can further customize the behavior of OptionButton3, OptionButton4, and so on by adding specific actions in their respective Click event handlers.
kuya wala po ba keo na naka excel na medyo nalilito na po kase kami e for 2days na namin ginagawa :(
 

Step 1: I-enable ang Developer Tab sa Excel


  1. Open Excel.
  2. Pumunta sa File > Options > Customize Ribbon.
  3. Sa Right Pane, i-check ang Developer box.
  4. I-click ang OK. Lalabas ang Developer tab sa Ribbon ng Excel.



Step 2: I-setup ang GroupBoxes at Option Buttons


  1. Sa Developer Tab, hanapin ang Insert button, at piliin ang mga Form Controls:
    • Piliin ang Group Box (Frame)na icon at gumawa ng dalawang Group Boxes sa sheet.
      • Group Box 1: Puwede mong i-label ito bilang "GroupBox1" at sa loob nito, i-create ang 5 Option Buttons (OptionButton1 to OptionButton5).
      • Group Box 2: I-label ito bilang "GroupBox2" at sa loob nito, i-create rin ang 5 Option Buttons (OptionButton6 to OptionButton10).
  2. Ayusin ang layout para malinaw ang pagkakakategorya ng mga Group Box at Option Buttons.



Step 3: Buksan ang VBA Editor


  1. Pindutin ang Alt + F11 para mabuksan ang VBA Editor.
  2. I-right-click ang iyong workbook mula sa Project Explorer (karaniwang makikita sa kaliwang bahagi ng VBA window).
  3. Piliin ang Insert > Module.



Step 4: Ipasok ang VBA Code


  1. Kopyahin ang code sa ibaba at i-paste ito sa module na nilikha mo:
    Code:
    Private Sub OptionButton1_Click()    ' Unlock GroupBox1 Option Buttons
        ToggleOptionButtons GroupBox:=1, LockState:=False
        ' Lock GroupBox2 Option Buttons
        ToggleOptionButtons GroupBox:=2, LockState:=True
    End Sub
    
    Private Sub OptionButton2_Click()
        ' Unlock both GroupBox1 and GroupBox2 Option Buttons
        ToggleOptionButtons GroupBox:=1, LockState:=False
        ToggleOptionButtons GroupBox:=2, LockState:=False
    End Sub
    
    Private Sub ToggleOptionButtons(GroupBox As Integer, LockState As Boolean)
        Dim OptionBtn As Object
        Dim StartIndex As Integer, EndIndex As Integer
    
        ' Set the range of Option Button names for each group box
        If GroupBox = 1 Then
            StartIndex = 1
            EndIndex = 5
        ElseIf GroupBox = 2 Then
            StartIndex = 6
            EndIndex = 10
        End If
    
        ' Loop through the option buttons in the specified group box
        For Each OptionBtn In ActiveSheet.OLEObjects
            If OptionBtn.progID = "Forms.OptionButton.1" Then
                If CInt(Mid(OptionBtn.Name, 12)) >= StartIndex And CInt(Mid(OptionBtn.Name, 12)) <= EndIndex Then
                    OptionBtn.Enabled = Not LockState
                End If
            End If
        Next OptionBtn
    End Sub

    Step 5: Bumalik sa Excel at I-Assign ang Macro
    1. Bumalik sa Excel (Alt + Q).
    2. I-right-click ang OptionButton1, at piliin ang Assign Macro.
    3. Piliin ang OptionButton1_Click, tapos i-click ang OK.
    4. I-right-click ang OptionButton2, at piliin ulit ang Assign Macro.
    5. Piliin ang OptionButton2_Click, tapos i-click ang OK.


      Step 6: Subukan ang Output
    6. I-test ang OptionButton1:
      • Kapag pinindot mo ang OptionButton1, dapat ma-unlock ang mga buttons sa GroupBox1 at ma-lock ang mga buttons sa GroupBox2.
    7. I-test ang OptionButton2:
      • Kapag pinindot mo ang OptionButton2, dapat ma-unlock ang parehong GroupBox1 at GroupBox2 buttons.

        Additional Notes
    8. Siguraduhin na ang mga pangalan ng iyong Option Buttons sa Excel ay eksaktong tumutugma sa mga pangalan sa code (hal., OptionButton1 to OptionButton10).
    9. I-enable ang Macro Settings:
      • Pumunta sa File &gt; Options &gt; Trust Center &gt; Trust Center Settings &gt; Macro Settings, at piliin ang "Enable all macros".
    10. Sa bawat pagbabago ng code, siguraduhing isave ang iyong file bilang isang Macro-Enabled Workbook (.xlsm).
 
1736396598424.webp


1736396644459.webp


di po ako IT. pero napagtripan lng po itong code. hehe

Private Sub OptionButton1_Click()
' Unlock GroupBox1's OptionButtons
OptionButton1.Enabled = True
OptionButton2.Enabled = True
OptionButton3.Enabled = True
OptionButton4.Enabled = True
OptionButton5.Enabled = True

' Lock GroupBox2's OptionButtons
OptionButton6.Enabled = False
OptionButton7.Enabled = False
OptionButton8.Enabled = False
OptionButton9.Enabled = False
OptionButton10.Enabled = False
End Sub

Private Sub OptionButton2_Click()
' Unlock all OptionButtons
OptionButton1.Enabled = True
OptionButton2.Enabled = True
OptionButton3.Enabled = True
OptionButton4.Enabled = True
OptionButton5.Enabled = True
OptionButton6.Enabled = True
OptionButton7.Enabled = True
OptionButton8.Enabled = True
OptionButton9.Enabled = True
OptionButton10.Enabled = True
End Sub

Private Sub UserForm_Initialize()
' Lock GroupBox2's OptionButtons initially
OptionButton6.Enabled = False
OptionButton7.Enabled = False
OptionButton8.Enabled = False
OptionButton9.Enabled = False
OptionButton10.Enabled = False
End Sub
 
View attachment 3396319

View attachment 3396322

di po ako IT. pero napagtripan lng po itong code. hehe

Private Sub OptionButton1_Click()
' Unlock GroupBox1's OptionButtons
OptionButton1.Enabled = True
OptionButton2.Enabled = True
OptionButton3.Enabled = True
OptionButton4.Enabled = True
OptionButton5.Enabled = True

' Lock GroupBox2's OptionButtons
OptionButton6.Enabled = False
OptionButton7.Enabled = False
OptionButton8.Enabled = False
OptionButton9.Enabled = False
OptionButton10.Enabled = False
End Sub

Private Sub OptionButton2_Click()
' Unlock all OptionButtons
OptionButton1.Enabled = True
OptionButton2.Enabled = True
OptionButton3.Enabled = True
OptionButton4.Enabled = True
OptionButton5.Enabled = True
OptionButton6.Enabled = True
OptionButton7.Enabled = True
OptionButton8.Enabled = True
OptionButton9.Enabled = True
OptionButton10.Enabled = True
End Sub

Private Sub UserForm_Initialize()
' Lock GroupBox2's OptionButtons initially
OptionButton6.Enabled = False
OptionButton7.Enabled = False
OptionButton8.Enabled = False
OptionButton9.Enabled = False
OptionButton10.Enabled = False
End Sub
Beatriz bei
 
Status
Not open for further replies.

About this Thread

  • 27
    Replies
  • 890
    Views
  • 4
    Participants
Last reply from:
Jorgyy

Trending Topics

Online now

Members online
942
Guests online
1,243
Total visitors
2,185

Forum statistics

Threads
2,274,068
Posts
28,953,457
Members
1,235,042
Latest member
janjan99
Back
Top