I can populate combobox1 which activates a pivot table to populate combobox2. I need to populate texbox1 with information based on the selections. Below is the code I used and I am stumped as to how to modify or add to this in order to populate my textbox1.
Please Help!
Sub FillCombo1()
Dim Cell As Range
Dim i As Single
Dim shpobj As Object
Sheets("GMTable").Visible = True
Set Cell = Worksheets("GMTable").Range("Table1")
For Each shpobj In Worksheets("2-1").OLEObjects
If shpobj.Name = "ComboBox1" Then
shpobj.Object.Clear
For i = 1 To Cell.ListObject.Range.Columns.Count
shpobj.Object.AddItem Cell.ListObject.Range.Cells(1, i)
Next i
End If
Next shpobj
Sheets("GMTable").Visible = False
Application.ScreenUpdating = False
End Sub
Sub FillCombo2()
Dim i, r As Single
Dim shpobj As Object
Dim rng, Value As Variant
Sheets("GMPivot").Visible = True
Application.ScreenUpdating = False
Worksheets("GMPivot").PivotTables("PivotTable1").PivotCache.Refresh
On Error Resume Next
For Each ptfl In Worksheets("GMPivot").PivotTables("PivotTable1").PivotFields
ptfl.Orientation = xlHidden
Next ptfl
On Error GoTo 0
For Each shpobj In Worksheets("2-1").OLEObjects
'If shpobj.Name = "ComboBox1" And shpobj.Object.Value = "" Then Exit For
If shpobj.Name = "ComboBox1" Then
Worksheets("GMPivot").PivotTables("PivotTable1") _
.PivotFields(shpobj.Object.Value).Orientation = xlRowField
Worksheets("GMPivot").Select
Application.Calculate
End If
If shpobj.Name = "ComboBox2" Then
shpobj.Object.Clear
shpobj.Object.List = Worksheets("GMPivot").PivotTables("PivotTable1").RowRange.Value
shpobj.Object.RemoveItem 0
shpobj.Object.RemoveItem _
Worksheets("GMPivot").PivotTables("PivotTable1").RowRange.Rows.Count - 2
End If
Next shpobj
Sheets("GMPivot").Visible = False
Application.ScreenUpdating = False
Worksheets("2-1").Select
Application.ScreenUpdating = True
End Sub
Bookmarks