Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 237
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I copy only sub-totalled values - without any detail? Parkperson Excel Worksheet Functions 1 December 16th 04 08:26 PM
Texbox values based on Combobox Value(more detail) Todd Huttenstine[_2_] Excel Programming 6 November 10th 03 01:49 PM
Having data populate text boxes based on Combobox Value Todd Huttenstine[_2_] Excel Programming 1 November 10th 03 01:35 AM
Combobox populating based on Option Button Todd Huttenstine[_2_] Excel Programming 7 November 9th 03 10:18 PM
ComboBox Values Darren[_3_] Excel Programming 1 July 16th 03 10:41 AM


All times are GMT +1. The time now is 07:00 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"