Hey Gurus,
I have been grinding my way through this learning process for about 3-4 weeks now and have used alot of resources. Any and All input is welcome.
Any suggestions on Code for any step in this is welcome. I'm really trying to begin learning VBA and impress my Boss and raise my value at work by learning and adding a couple of notches in my belt. Thanks in advance!
Part 1 - Whats, What so far
Part 2 - ISSUES
Currently at this point in this Project the following sources, along with many other random sources, were used to get me this far:
https://www.youtube.com/watch?v=1HH5iBdG7xw
https://www.youtube.com/watch?v=yMO_wCZgQbc
https://www.youtube.com/watch?v=FW89ITnAq2Q
The thing that makes this a little more difficult is the fact that I am not wanting to create separate columns for each "Sub-Category" and list all of its options. I would have been done 3 weeks ago if that was the case.
The data is from Sheets("DATA") and the combobox's are on Sheets("CHART"). There DATA sheet is always going to be changing so my drop downs are based on Dynamic Named Ranges.
Dynamic Named Ranges
Dynamic Named Ranges catagorymain subcatagorymain locationmain custmain [TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[TD]Category[/TD]
[TD]SUB-CATEGORY[/TD]
[TD]LOCATION[/TD]
[TD]CUSTOMER[/TD]
[TD]TOTAL[/TD]
[/TR]
[TR]
[TD](All)[/TD]
[TD](All)[/TD]
[TD](All)[/TD]
[TD](All)[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Accumulator[/TD]
[TD]Accumulator[/TD]
[TD]CAR[/TD]
[TD]XXXX[/TD]
[TD]$x.xx[/TD]
[/TR]
[TR]
[TD]Accumulator[/TD]
[TD]Accumulator[/TD]
[TD]WCND[/TD]
[TD]YYYY[/TD]
[TD]$x.xx[/TD]
[/TR]
[TR]
[TD]Accumulator[/TD]
[TD]Accumulator[/TD]
[TD]WCND[/TD]
[TD]YYYY[/TD]
[TD]$x.xx[/TD]
[/TR]
[TR]
[TD]Flange, Adapter[/TD]
[TD]11"5M[/TD]
[TD]BCA[/TD]
[TD]YYYY[/TD]
[TD]$x.xx[/TD]
[/TR]
[TR]
[TD]Flange, Adapter[/TD]
[TD]11"5M[/TD]
[TD]ODTX[/TD]
[TD]XXXX[/TD]
[TD]$x.xx[/TD]
[/TR]
[TR]
[TD]Flange, Adapter[/TD]
[TD]13-5/8"10M[/TD]
[TD]CAR[/TD]
[TD]AAAA[/TD]
[TD]$x.xx[/TD]
[/TR]
[TR]
[TD]Flange, Adapter[/TD]
[TD]WECO[/TD]
[TD]CPA[/TD]
[TD]AAAA[/TD]
[TD]$x.xx[/TD]
[/TR]
[TR]
[TD]Gate Valve[/TD]
[TD]HWO - 1-13/16"10M[/TD]
[TD]CPA[/TD]
[TD]BBBB[/TD]
[TD]$x.xx[/TD]
[/TR]
[TR]
[TD]Gate Valve[/TD]
[TD]HWO - 1-13/16"10M[/TD]
[TD]OKC[/TD]
[TD]BBBB[/TD]
[TD]$x.xx[/TD]
[/TR]
[TR]
[TD]Gate Valve[/TD]
[TD]HWO - 7-1/16"10M[/TD]
[TD]OKC[/TD]
[TD]CCCC[/TD]
[TD]$x.xx[/TD]
[/TR]
[TR]
[TD]Gate Valve[/TD]
[TD]HWO - 7-1/16"10M[/TD]
[TD]CPA[/TD]
[TD]DDDD[/TD]
[TD]$x.xx[/TD]
[/TR]
[TR]
[TD]Gate Valve[/TD]
[TD]HWO - 2-1/16"5M[/TD]
[TD]WCND[/TD]
[TD]DDDD[/TD]
[TD]$x.xx[/TD]
[/TR]
[TR]
[TD]Gate Valve[/TD]
[TD]HWO - 2-1/16"5M[/TD]
[TD]CAR[/TD]
[TD]AAAA[/TD]
[TD]$x.xx[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
The Data is put into PivotTable1 on ThisWorkBook.Sheets("Pivot") and a PivotChart was created and is on ThisWorkBook.Sheets("CHART").
I have 4 ComboBoxes that I want to use to drill down. As the user choses the category in ComboBox1(cmbRent) a macro changes the PivotFilter on ("Pivot") It changes the PivotChart on ("CHART") using named ranges [selCat] and [fltCat].
This fills my first ActiveX ComboBox called cmbRent and produces a unique list.
It is called at the time the Workbook is opened. it is located on "This Workbook".
This is the code that is used to change the pivotTable and PivotChart based on the selction. My ComboBoxes are linked to the name ranges on ("CHART") so when a selction is made it populates in the respective named range. I am having issues with this code not working all of the time, maybe because i have be messing with it so much, HA! I would like some help with this one as well.
Here is the ("CHARTS") page
And here is the ("Pivot") page
To be Cont.
I have been grinding my way through this learning process for about 3-4 weeks now and have used alot of resources. Any and All input is welcome.
Any suggestions on Code for any step in this is welcome. I'm really trying to begin learning VBA and impress my Boss and raise my value at work by learning and adding a couple of notches in my belt. Thanks in advance!
Part 1 - Whats, What so far
Part 2 - ISSUES
Currently at this point in this Project the following sources, along with many other random sources, were used to get me this far:
https://www.youtube.com/watch?v=1HH5iBdG7xw
https://www.youtube.com/watch?v=yMO_wCZgQbc
https://www.youtube.com/watch?v=FW89ITnAq2Q
The thing that makes this a little more difficult is the fact that I am not wanting to create separate columns for each "Sub-Category" and list all of its options. I would have been done 3 weeks ago if that was the case.
The data is from Sheets("DATA") and the combobox's are on Sheets("CHART"). There DATA sheet is always going to be changing so my drop downs are based on Dynamic Named Ranges.
Dynamic Named Ranges
Code:
catagorymain =OFFSET(DATA!$A$2,0,0,COUNTA(DATA!$A$2:$A$9890))
subcatagorymain =OFFSET(DATA!$B$2,0,0,COUNTA(DATA!$B$2:$B$9890))
locationmain =OFFSET(DATA!$C$2,0,0,COUNTA(DATA!$C$2:$C$9890))
custmain =OFFSET(DATA!$D$2,0,0,COUNTA(DATA!$D$2:$D$9890))
Dynamic Named Ranges catagorymain subcatagorymain locationmain custmain [TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[TD]Category[/TD]
[TD]SUB-CATEGORY[/TD]
[TD]LOCATION[/TD]
[TD]CUSTOMER[/TD]
[TD]TOTAL[/TD]
[/TR]
[TR]
[TD](All)[/TD]
[TD](All)[/TD]
[TD](All)[/TD]
[TD](All)[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Accumulator[/TD]
[TD]Accumulator[/TD]
[TD]CAR[/TD]
[TD]XXXX[/TD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-1/16"5M[/TD]
[TD]CAR[/TD]
[TD]AAAA[/TD]
[TD]$x.xx[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
The Data is put into PivotTable1 on ThisWorkBook.Sheets("Pivot") and a PivotChart was created and is on ThisWorkBook.Sheets("CHART").
I have 4 ComboBoxes that I want to use to drill down. As the user choses the category in ComboBox1(cmbRent) a macro changes the PivotFilter on ("Pivot") It changes the PivotChart on ("CHART") using named ranges [selCat] and [fltCat].
This fills my first ActiveX ComboBox called cmbRent and produces a unique list.
Code:
Sub FillCombos()
Dim TABLE As Worksheet
Dim DATA As Worksheet
Set ch = ThisWorkbook.Sheets("CHART")
Set da = ThisWorkbook.Sheets("DATA")
' Last Row
daLR = da.Cells(Rows.Count, 1).End(xlUp).Row
FirstTime = True
' Loop thru rows
For X = 2 To daLR
If da.Cells(X, 1) <> "" And (InStr(blah, "|" & da.Cells(X, 1) & "|") = 0) Then
If FirstTime = True Then
FirstTime = False
blah = "|" & blah & da.Cells(X, 1) & "|"
Else
blah = blah & da.Cells(X, 1) & "|"
End If
End If
Next X
myArray = Split(blah, "|")
Sheet7.cmbRent.Clear
For Each cell In myArray
If cell <> "" Then
Sheet7.cmbRent.AddItem (cell)
End If
Next cell
ThisWorkbook.Sheets("CHART").cmbRent.ListIndex = 0
End Sub
It is called at the time the Workbook is opened. it is located on "This Workbook".
Code:
Private Sub Workbook_Open()
Call FillCombos
End Sub
This is the code that is used to change the pivotTable and PivotChart based on the selction. My ComboBoxes are linked to the name ranges on ("CHART") so when a selction is made it populates in the respective named range. I am having issues with this code not working all of the time, maybe because i have be messing with it so much, HA! I would like some help with this one as well.
Code:
Sub FilterCat()
Dim pt As PivotTable
Dim ws As Worksheet
Set pt = Sheets("Pivot").PivotTables("PivotTable1")
Set ws = ThisWorkbook.Sheets("CHART")
[fltCat] = [selCat]
If ws.Range("selCat") = "(All)" Then
pt.PivotFields("CATEGORY").ClearAllFilters
End If
Here is the ("CHARTS") page
And here is the ("Pivot") page
To be Cont.