Hello forum!
Currently we have a table of client data with multiple categories of details, something like this:
Our ultimate goal is to translate this file of data into a pivot table, where it counts based on the conditions (let's say from columns AU:BC), to something like this:
However, we can't seem to figure out an effective way, so we resorted to using VBA so that the script can automatically copy the data from the main table to another sheet and sort them accordingly for the pivot table to extract the data. Ideally, the copied data should appear to be something like this:
However, on our VBA, it only seemed to work out well on the first portion of our script, it ended up being in this state after we ran the script:
Here is the VBA code that we tried:
It seemed that our script had some issues with detecting the last row, and that is mostly where it got messed up.
Mainly we need help with the VBA, however as I mentioned earlier, the main goal was getting the pivot table, perhaps there is a better alternative, feel free to suggest, we are fine with it too. Any help would be greatly appreciated, do let me know if you need our Excel file as well. Thanks in advance!
Currently we have a table of client data with multiple categories of details, something like this:
Our ultimate goal is to translate this file of data into a pivot table, where it counts based on the conditions (let's say from columns AU:BC), to something like this:
However, we can't seem to figure out an effective way, so we resorted to using VBA so that the script can automatically copy the data from the main table to another sheet and sort them accordingly for the pivot table to extract the data. Ideally, the copied data should appear to be something like this:
However, on our VBA, it only seemed to work out well on the first portion of our script, it ended up being in this state after we ran the script:
Here is the VBA code that we tried:
VBA Code:
Sub IntermediateCalc()
Sheets("Master Data").Range("AU8:AY8").Copy
Sheets("Working - Domains").Range("B2").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
DomainBLastRow = Sheets("Working - Domains").Range("B" & Rows.Count).End(xlUp).Row
Sheets("Master Data").Range("AZ8:BC8").Copy
Sheets("Working - Domains").Range("C" & DomainBLastRow + 1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
DomainCLastRow = Sheets("Working - Domains").Range("C" & Rows.Count).End(xlUp).Row
Sheets("Master Data").Range("D8").Copy
Sheets("Working - Domains").Range("A2:A" & DomainCLastRow).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ClientLastRow = Sheets("Master Data").Range("D" & Rows.Count).End(xlUp).Row
Dim Cell As Range
For Each Cell In Sheets("Master Data").Range("D9:D11")
If Cell <> "" Then
Range(Cell.Offset(0, 43), Cell.Offset(0, 47)).Copy
Sheets("Working - Domains").Range("B" & DomainCLastRow + 1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=True
VariableBLastRow = Sheets("Working - Domains").Range("B" & Rows.Count).End(xlUp).Row
Range(Cell.Offset(0, 48), Cell.Offset(0, 51)).Copy
Sheets("Working - Domains").Range("C" & VariableBLastRow + 1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=True
VariableCLastRow = Sheets("Working - Domains").Range("C" & Rows.Count).End(xlUp).Row
'Cell.Copy
'Sheets("Working - Domains").Range("A" & DomainCLastRow + 1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Else
MsgBox "Update Complete"
End If
Next Cell
End Sub
It seemed that our script had some issues with detecting the last row, and that is mostly where it got messed up.
Mainly we need help with the VBA, however as I mentioned earlier, the main goal was getting the pivot table, perhaps there is a better alternative, feel free to suggest, we are fine with it too. Any help would be greatly appreciated, do let me know if you need our Excel file as well. Thanks in advance!