Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Texbox values based on Combobox Value(more detail)
Hey Tom,
I finally got it to work. Thank you for your help. I had to remove the Option Explicit part. That was the reason I was receiving the error. Below is what I removed from the top of the entire module: ******* Option Explicit Dim cLastRow As Long Dim i As Long ******** Instead of using the Option Explicit, I just copied the 2 lines of code to each of the 3 OptionButton code (which it pertains to). Do you know why when I removed the Option Explicit, it worked? Below is the code you wrtoe that I am using. "Here is the second piece of code, copied out of a working module:" Private Sub Combobox1_Click() If ComboBox1.ListIndex < -1 Then With Worksheets("sheet2") If OptionButton1.Value Then Set rng = .Range("A2:A52") ElseIf OptionButton2.Value Then Set rng = .Range("B2:B52") Else Set rng = .Range("C2:C52") End If For Each cell In rng If cell.Text = ComboBox1.Value Then TextBox1.Value = .Cells(cell.Row, 1).Value TextBox2.Value = .Cells(cell.Row, 2).Value TextBox3.Value = .Cells(cell.Row, 3).Value Exit For End If Next End With End If End Sub Thanx again, Todd |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Texbox values based on Combobox Value(more detail)
Option Explicit requires all variables to be declared - always a good
practice. If you want it in your code you need to declare variables such as this: Private Sub Combobox1_Click() dim rng as Range dim cell as Range If ComboBox1.ListIndex < -1 Then With Worksheets("sheet2") If OptionButton1.Value Then Set rng = .Range("A2:A52") ElseIf OptionButton2.Value Then Set rng = .Range("B2:B52") Else Set rng = .Range("C2:C52") End If For Each cell In rng If cell.Text = ComboBox1.Value Then TextBox1.Value = .Cells(cell.Row, 1).Value TextBox2.Value = .Cells(cell.Row, 2).Value TextBox3.Value = .Cells(cell.Row, 3).Value Exit For End If Next End With End If End Sub -- Regards, Tom Ogilvy Todd Huttenstine wrote in message ... Hey Tom, I finally got it to work. Thank you for your help. I had to remove the Option Explicit part. That was the reason I was receiving the error. Below is what I removed from the top of the entire module: ******* Option Explicit Dim cLastRow As Long Dim i As Long ******** Instead of using the Option Explicit, I just copied the 2 lines of code to each of the 3 OptionButton code (which it pertains to). Do you know why when I removed the Option Explicit, it worked? Below is the code you wrtoe that I am using. "Here is the second piece of code, copied out of a working module:" Private Sub Combobox1_Click() If ComboBox1.ListIndex < -1 Then With Worksheets("sheet2") If OptionButton1.Value Then Set rng = .Range("A2:A52") ElseIf OptionButton2.Value Then Set rng = .Range("B2:B52") Else Set rng = .Range("C2:C52") End If For Each cell In rng If cell.Text = ComboBox1.Value Then TextBox1.Value = .Cells(cell.Row, 1).Value TextBox2.Value = .Cells(cell.Row, 2).Value TextBox3.Value = .Cells(cell.Row, 3).Value Exit For End If Next End With End If End Sub Thanx again, Todd |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How do I copy only sub-totalled values - without any detail? | Excel Worksheet Functions | |||
Texbox values based on Combobox Value(more detail) | Excel Programming | |||
Having data populate text boxes based on Combobox Value | Excel Programming | |||
Combobox populating based on Option Button | Excel Programming | |||
ComboBox Values | Excel Programming |