PDA

View Full Version : How to Link 2Combo Box select Date and Cell name



lotto009
04-13-2013, 04:44 AM
Dear all VBA Expert
I would like to select
-Select Combobox_1 Put cell name
-Select Combobox_2 Select Date from list
-Show 2Chart next sheet(I have 3 sheet )
Coould you see my file upload as bolw my VBA
Thank you
lotto009:(
Private Sub ComboBox1_Change()
Sheets("HO Attemp").Range("$A$1:$H$200000").AutoFilter Field:=2, Criteria1:=ComboBox1, Operator:=xlAnd
End Sub
Private Sub ComboBox2_Change()
Sheets("PropagationDelay_TP").Range("$A$1:$N$200000").AutoFilter Field:=2, Criteria1:=ComboBox1, Operator:=xlAnd
End Sub

SamT
04-13-2013, 07:15 AM
These examples need modify to work for you.

HO Attemp Code
Worksheet_SelectionChange(Target As Excel.Range)
Load UserForm1
UserForm1.ComboBox1.Text = Target.Text
UserForm1.Show


UseForm1 Code:
Sub ComboBox1_Change()
ComboBox2.Text = Sheets("HO Attemp").Range("$A$1:$H$200000").AutoFilter Field:=2, Criteria1:=ComboBox1, Operator:=xlAnd
End Sub

lotto009
04-13-2013, 08:11 AM
Dear Samt
Thank you for your kindly support tom but I no used UseForm1 Code above
plese help see my file att because I write vb on sheet name CHART has 2 Combo Box
lotto009

lotto009
04-13-2013, 08:13 AM
:banghead:
Dear Samt
Thank you for your kindly support tom but I no used UseForm1 Code above
plese help see my file att because I write vb on sheet name CHART has 2 Combo Box
lotto009

Tinbendr
04-14-2013, 09:27 PM
Here's one option.

This uses collections to get a unique list. But Charts aren't my strong suit, but maybe this will give you some ideas.

Private Sub CommandButton1_Click()
Dim WB As Workbook
Dim myHo As Worksheet
Dim LastRow As Long
Dim C1 As New Collection
Dim C2 As New Collection
Dim A As Long
Dim B As Long

Set WB = ActiveWorkbook
Set myHo = WB.Worksheets("HO Attemp")

LastRow = myHo.Cells(Rows.Count, 1).End(xlUp).Row

myHo.AutoFilterMode = False
WB.Worksheets("PropagationDelay_TP").AutoFilterMode = False

ComboBox1.Clear

'Iterates through Col C and only inserts unique cellnames into Combobox1
For A = 2 To LastRow
On Error Resume Next
C1.Add myHo.Range("C" & A).Text, myHo.Range("C" & A).Text
Next

On Error GoTo 0
For B = 1 To C1.Count
ComboBox1.AddItem C1(B)
Next

'Iterates through Col A and only inserts unique dates into Combobox2
ComboBox2.Clear

For A = 2 To LastRow
On Error Resume Next
C2.Add myHo.Range("A" & A).Text, myHo.Range("A" & A).Text
Next

On Error GoTo 0
For B = 1 To C2.Count
ComboBox2.AddItem C2(B)
Next

End Sub

lotto009
04-14-2013, 10:43 PM
Dear David
Thank you for help I put you VB to Chart can put but chart no moving to them I dot hase iideas becasue I has problem long time this cause:think:

Tinbendr
04-16-2013, 04:25 AM
OK, try this out I think I have it working.

When you click the refresh button, it takes a couple of seconds for it to update, so be patient.

Private Sub ComboBox1_Change()
Sheets("HO Attemp").Range("$A$1:$H$200000").AutoFilter Field:=2, Criteria1:=ComboBox1, Operator:=xlAnd

End Sub


Private Sub ComboBox2_Change()
Sheets("PropagationDelay_TP").Range("$A$1:$N$200000").AutoFilter Field:=1, Criteria1:=ComboBox2, Operator:=xlAnd
End Sub
Private Sub CommandButton1_Click()
Dim WB As Workbook
Dim myHo As Worksheet
Dim MyProp As Worksheet
Dim LastRow As Long
Dim C1 As New Collection
Dim C2 As New Collection
Dim A As Long
Dim B As Long

Set WB = ActiveWorkbook
Set myHo = WB.Worksheets("HO Attemp")
Set MyProp = WB.Worksheets("PropagationDelay_TP")

'Has to come first
ComboBox1.Clear
ComboBox2.Clear

'Has to come second
myHo.AutoFilterMode = False
MyProp.AutoFilterMode = False

'Has to come third
Workbooks(1).RefreshAll

LastRow = myHo.Cells(Rows.Count, 1).End(xlUp).Row

'Iterates through Col C and only inserts unique cellnames into Combobox1
For A = 2 To LastRow
On Error Resume Next
C1.Add MyProp.Range("B" & A).Text, MyProp.Range("B" & A).Text
Next

On Error GoTo 0
For B = 1 To C1.Count
ComboBox1.AddItem C1(B)
Next

LastRow = myHo.Cells(Rows.Count, 1).End(xlUp).Row
'Iterates through Col A and only inserts unique dates into Combobox2
For A = 2 To LastRow
On Error Resume Next
C2.Add myHo.Range("A" & A).Text, myHo.Range("A" & A).Text
Next

On Error GoTo 0
For B = 1 To C2.Count
ComboBox2.AddItem C2(B)
Next

End Sub

lotto009
04-16-2013, 07:07 AM
Dear david
Thank you sincerely trying to solve my problem.
-Chart HO Attemp just OK I can used from your vba code.
-ChartPropagationDelay_TP need show day by day same chart HO Attemp.
Could you advise code vba because ChartPropagationDelay_TP show all day I need show same day Chart HO Attemp can see photo
Sincerely
lotto009:bow: