populate values in textbox based on optionbutton doesn't work

Maklil

Board Regular
Joined
Jun 23, 2022
Messages
174
Office Version
  1. 2019
Platform
  1. Windows
Hello
I try to populate values in textbox based on select optionbuttonS after select combobox.
so should brings the values from cloumn F when select combobox1 and optionbutton1 into textbox1,and if I select combobox1 and optionbutton2 should brings the values from cloumn G and populate into textbox1.


VBA Code:
Private Sub ComboBox1_Change()
Dim c As Range
With Sheets("BS")
  
    Set c = .Range("B:B").Find(What:=ComboBox1.Value, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, _
    SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
    If OptionButton1.Value = True Then
    If Not c Is Nothing Then
        ComboBox2.Value = c.Offset(, 1).Value
        ComboBox3.Value = c.Offset(, 2).Value
        ComboBox4.Value = c.Offset(, 3).Value
        TextBox1.Value = c.Offset(, 5).Value
        ElseIf OptionButton2.Value = True Then
        If Not c Is Nothing Then
        ComboBox2.Value = c.Offset(, 1).Value
        ComboBox3.Value = c.Offset(, 2).Value
        ComboBox4.Value = c.Offset(, 3).Value
        TextBox1.Value = c.Offset(, 6).Value
        End If
    End If
    End If
End With

End Sub
How can I do that ,please
 
you count from the search column so column C = 1, D = 2 on so on
umm ! thanks for this clarification

Using your code, Textbox value is returned from Column F for optionbutton1 & Column G for optionbutton2
do you mean like this?
VBA Code:
Private Sub OptionButton1_Click()
    
     If Me.OptionButton1.Value = True Then
            Me.TextBox1.Value = c.Offset(, 4).Value
            End If
End Sub
actually doesn't succeed and gives error object required in this line
VBA Code:
            Me.TextBox1.Value = c.Offset(, 4).Value

but if you mean put whole procdure like this
VBA Code:
Private Sub OptionButton1_Click()
    
     Dim c       As Range, rng As Range
    Dim search  As String
    
    Set rng = ThisWorkbook.Worksheets("BS").Range("B:B")
    
    search = Me.ComboBox1.Value
    
    Set c = rng.Find(What:=search, LookIn:=xlValues, LookAt:=xlWhole, _
                     SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, _
                    SearchFormat:=False)
                    
    If Not c Is Nothing Then
    Me.ComboBox2.Value = c.Offset(, 1).Value
        Me.ComboBox3.Value = c.Offset(, 2).Value
        Me.ComboBox4.Value = c.Offset(, 3).Value
        Me.TextBox1.Value = c.Offset(, 4).Value
        End If
End Sub
then it works .
 
Upvote 0

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
None of that - I used the codes you published in #Post 7 along with the updated combobox1_change code & that worked ok but as I stated, it needs a value in combobox1 that can be found in the search range.

Dave
 
Upvote 0
but as I stated, it needs a value in combobox1 that can be found in the search range.
yes you'r right the number of combobox is not right that's why doesn't change the value when move from optionbutton to another
now everyting is great !(y)
I appreciated for your time and help;)
 
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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