I have an excel table which is generated by VBA from several raw data files. the generated table includes a column for some metrics. However, I am looking to generate some calculated metrics based on the existing metrics.
The calculation is for each line item. it takes the total unique visitor metric for each site, by month, by demographic, by media and divides it by the same metric for the "Sports" site category.
Can the gurus here suggest a way to execute the calculation within the existing VBA code: Below is the existing VBA and a sample of the final table i am looking for. Thanks.
<table style="border-collapse: collapse; width: 527pt;" width="701" border="0" cellpadding="0" cellspacing="0"><col style="width: 48pt;" width="64"> <col style="width: 41pt;" width="54"> <col style="width: 87pt;" width="116"> <col style="width: 92pt;" width="122"> <col style="width: 143pt;" width="191"> <col style="width: 57pt;" width="76"> <col style="width: 59pt;" width="78"> <tbody><tr style="height: 15pt;" height="20"> <td class="xl70" style="height: 15pt; width: 48pt;" width="64" height="20">
</td> <td class="xl71" style="width: 41pt;" width="54">A</td> <td class="xl70" style="width: 87pt;" width="116">B</td> <td class="xl70" style="width: 92pt;" width="122">C</td> <td class="xl70" style="width: 143pt;" width="191">D</td> <td class="xl70" style="width: 57pt;" width="76">E</td> <td class="xl70" style="width: 59pt;" width="78">F</td> </tr> <tr style="height: 15pt;" height="20"> <td class="xl70" style="height: 15pt;" height="20">
</td> <td class="xl65">Month</td> <td class="xl65">Demographic</td> <td class="xl65">Media</td> <td class="xl65">Metric</td> <td class="xl65">Property</td> <td class="xl65">Value</td> </tr> <tr style="height: 15pt;" height="20"> <td class="xl70" style="height: 15pt;" height="20">2</td> <td class="xl66">Jul-07</td> <td class="xl65">Male: 18-24</td> <td class="xl65">Sports Category</td> <td class="xl65">Total Unique Visitors (000)</td> <td class="xl69"> Sports</td> <td class="xl67">4,309</td> </tr> <tr style="height: 15pt;" height="20"> <td class="xl70" style="height: 15pt;" height="20">3</td> <td class="xl66">Aug-07</td> <td class="xl65">Male: 18-24</td> <td class="xl65">Sports Category</td> <td class="xl65">Total Unique Visitors (000)</td> <td class="xl69"> Sports</td> <td class="xl67">4,743</td> </tr> <tr style="height: 15pt;" height="20"> <td class="xl70" style="height: 15pt;" height="20">4</td> <td class="xl66">Sep-07</td> <td class="xl65">Male: 18-24</td> <td class="xl65">Sports Category</td> <td class="xl65">Total Unique Visitors (000)</td> <td class="xl69"> Sports</td> <td class="xl67">5,242</td> </tr> <tr style="height: 15pt;" height="20"> <td class="xl70" style="height: 15pt;" height="20">5</td> <td class="xl66">Jul-07</td> <td class="xl65">Male: 18-24</td> <td class="xl65">Sports Category</td> <td class="xl65">Total Unique Visitors (000)</td> <td class="xl69">Site 1</td> <td class="xl67">1,593</td> </tr> <tr style="height: 15pt;" height="20"> <td class="xl70" style="height: 15pt;" height="20">6</td> <td class="xl66">Aug-07</td> <td class="xl65">Male: 18-24</td> <td class="xl65">Sports Category</td> <td class="xl65">Total Unique Visitors (000)</td> <td class="xl69">Site 1</td> <td class="xl67">1,989</td> </tr> <tr style="height: 15pt;" height="20"> <td class="xl70" style="height: 15pt;" height="20">7</td> <td class="xl66">Sep-07</td> <td class="xl65">Male: 18-24</td> <td class="xl65">Sports Category</td> <td class="xl65">Total Unique Visitors (000)</td> <td class="xl69">Site 1</td> <td class="xl67">2,511</td> </tr> <tr style="height: 15pt;" height="20"> <td class="xl70" style="height: 15pt;" height="20">8</td> <td class="xl66">Jul-07</td> <td class="xl65">Male: 18-24</td> <td class="xl65">Sports Category</td> <td class="xl65">Total Unique Visitors (000)</td> <td class="xl69">Site 2</td> <td class="xl67">1,184</td> </tr> <tr style="height: 15pt;" height="20"> <td class="xl70" style="height: 15pt;" height="20">9</td> <td class="xl66">Aug-07</td> <td class="xl65">Male: 18-24</td> <td class="xl65">Sports Category</td> <td class="xl65">Total Unique Visitors (000)</td> <td class="xl69">Site 2</td> <td class="xl67">1,549</td> </tr> <tr style="height: 15pt;" height="20"> <td class="xl70" style="height: 15pt;" height="20">10</td> <td class="xl66">Sep-07</td> <td class="xl65">Male: 18-24</td> <td class="xl65">Sports Category</td> <td class="xl65">Total Unique Visitors (000)</td> <td class="xl69">Site 2</td> <td class="xl67">1,863</td> </tr> <tr style="height: 15pt;" height="20"> <td class="xl73" colspan="4" style="height: 15pt;" height="20">additional calculated part to generate</td> <td>
</td> <td class="xl69">
</td> <td class="xl68">
</td> </tr> <tr style="height: 15pt;" height="20"> <td class="xl70" style="height: 15pt;" height="20">12</td> <td class="xl66">Jul-07</td> <td class="xl65">Male: 18-24</td> <td class="xl65">Sports Category</td> <td class="xl65">calculated metric : reach</td> <td class="xl69">Site 1</td> <td class="xl67">F5/F2</td> </tr> <tr style="height: 15pt;" height="20"> <td class="xl70" style="height: 15pt;" height="20">13</td> <td class="xl66">Aug-07</td> <td class="xl65">Male: 18-24</td> <td class="xl65">Sports Category</td> <td class="xl65">calculated metric : reach</td> <td class="xl69">Site 1</td> <td class="xl67">F6/F3</td> </tr> <tr style="height: 15pt;" height="20"> <td class="xl70" style="height: 15pt;" height="20">14</td> <td class="xl66">Sep-07</td> <td class="xl65">Male: 18-24</td> <td class="xl65">Sports Category</td> <td class="xl65">calculated metric : reach</td> <td class="xl69">Site1</td> <td class="xl67">F7/F4</td> </tr> <tr style="height: 15pt;" height="20"> <td class="xl70" style="height: 15pt;" height="20">15</td> <td class="xl66">Jul-07</td> <td class="xl65">Male: 18-24</td> <td class="xl65">Sports Category</td> <td class="xl65">calculated metric : reach</td> <td class="xl69">Site 2</td> <td class="xl67">F9/F2</td> </tr> <tr style="height: 15pt;" height="20"> <td class="xl70" style="height: 15pt;" height="20">16</td> <td class="xl66">Aug-07</td> <td class="xl65">Male: 18-24</td> <td class="xl65">Sports Category</td> <td class="xl65">calculated metric : reach</td> <td class="xl69">Site 2</td> <td class="xl67">F10/F3</td> </tr> <tr style="height: 15pt;" height="20"> <td class="xl70" style="height: 15pt;" height="20">17</td> <td class="xl66">Sep-07</td> <td class="xl65">Male: 18-24</td> <td class="xl65">Sports Category</td> <td class="xl65">calculated metric : reach</td> <td class="xl69">Site 2</td> <td class="xl67">F11/F4</td> </tr> </tbody></table>
The calculation is for each line item. it takes the total unique visitor metric for each site, by month, by demographic, by media and divides it by the same metric for the "Sports" site category.
Can the gurus here suggest a way to execute the calculation within the existing VBA code: Below is the existing VBA and a sample of the final table i am looking for. Thanks.
<table style="border-collapse: collapse; width: 527pt;" width="701" border="0" cellpadding="0" cellspacing="0"><col style="width: 48pt;" width="64"> <col style="width: 41pt;" width="54"> <col style="width: 87pt;" width="116"> <col style="width: 92pt;" width="122"> <col style="width: 143pt;" width="191"> <col style="width: 57pt;" width="76"> <col style="width: 59pt;" width="78"> <tbody><tr style="height: 15pt;" height="20"> <td class="xl70" style="height: 15pt; width: 48pt;" width="64" height="20">
</td> <td class="xl71" style="width: 41pt;" width="54">A</td> <td class="xl70" style="width: 87pt;" width="116">B</td> <td class="xl70" style="width: 92pt;" width="122">C</td> <td class="xl70" style="width: 143pt;" width="191">D</td> <td class="xl70" style="width: 57pt;" width="76">E</td> <td class="xl70" style="width: 59pt;" width="78">F</td> </tr> <tr style="height: 15pt;" height="20"> <td class="xl70" style="height: 15pt;" height="20">
</td> <td class="xl65">Month</td> <td class="xl65">Demographic</td> <td class="xl65">Media</td> <td class="xl65">Metric</td> <td class="xl65">Property</td> <td class="xl65">Value</td> </tr> <tr style="height: 15pt;" height="20"> <td class="xl70" style="height: 15pt;" height="20">2</td> <td class="xl66">Jul-07</td> <td class="xl65">Male: 18-24</td> <td class="xl65">Sports Category</td> <td class="xl65">Total Unique Visitors (000)</td> <td class="xl69"> Sports</td> <td class="xl67">4,309</td> </tr> <tr style="height: 15pt;" height="20"> <td class="xl70" style="height: 15pt;" height="20">3</td> <td class="xl66">Aug-07</td> <td class="xl65">Male: 18-24</td> <td class="xl65">Sports Category</td> <td class="xl65">Total Unique Visitors (000)</td> <td class="xl69"> Sports</td> <td class="xl67">4,743</td> </tr> <tr style="height: 15pt;" height="20"> <td class="xl70" style="height: 15pt;" height="20">4</td> <td class="xl66">Sep-07</td> <td class="xl65">Male: 18-24</td> <td class="xl65">Sports Category</td> <td class="xl65">Total Unique Visitors (000)</td> <td class="xl69"> Sports</td> <td class="xl67">5,242</td> </tr> <tr style="height: 15pt;" height="20"> <td class="xl70" style="height: 15pt;" height="20">5</td> <td class="xl66">Jul-07</td> <td class="xl65">Male: 18-24</td> <td class="xl65">Sports Category</td> <td class="xl65">Total Unique Visitors (000)</td> <td class="xl69">Site 1</td> <td class="xl67">1,593</td> </tr> <tr style="height: 15pt;" height="20"> <td class="xl70" style="height: 15pt;" height="20">6</td> <td class="xl66">Aug-07</td> <td class="xl65">Male: 18-24</td> <td class="xl65">Sports Category</td> <td class="xl65">Total Unique Visitors (000)</td> <td class="xl69">Site 1</td> <td class="xl67">1,989</td> </tr> <tr style="height: 15pt;" height="20"> <td class="xl70" style="height: 15pt;" height="20">7</td> <td class="xl66">Sep-07</td> <td class="xl65">Male: 18-24</td> <td class="xl65">Sports Category</td> <td class="xl65">Total Unique Visitors (000)</td> <td class="xl69">Site 1</td> <td class="xl67">2,511</td> </tr> <tr style="height: 15pt;" height="20"> <td class="xl70" style="height: 15pt;" height="20">8</td> <td class="xl66">Jul-07</td> <td class="xl65">Male: 18-24</td> <td class="xl65">Sports Category</td> <td class="xl65">Total Unique Visitors (000)</td> <td class="xl69">Site 2</td> <td class="xl67">1,184</td> </tr> <tr style="height: 15pt;" height="20"> <td class="xl70" style="height: 15pt;" height="20">9</td> <td class="xl66">Aug-07</td> <td class="xl65">Male: 18-24</td> <td class="xl65">Sports Category</td> <td class="xl65">Total Unique Visitors (000)</td> <td class="xl69">Site 2</td> <td class="xl67">1,549</td> </tr> <tr style="height: 15pt;" height="20"> <td class="xl70" style="height: 15pt;" height="20">10</td> <td class="xl66">Sep-07</td> <td class="xl65">Male: 18-24</td> <td class="xl65">Sports Category</td> <td class="xl65">Total Unique Visitors (000)</td> <td class="xl69">Site 2</td> <td class="xl67">1,863</td> </tr> <tr style="height: 15pt;" height="20"> <td class="xl73" colspan="4" style="height: 15pt;" height="20">additional calculated part to generate</td> <td>
</td> <td class="xl69">
</td> <td class="xl68">
</td> </tr> <tr style="height: 15pt;" height="20"> <td class="xl70" style="height: 15pt;" height="20">12</td> <td class="xl66">Jul-07</td> <td class="xl65">Male: 18-24</td> <td class="xl65">Sports Category</td> <td class="xl65">calculated metric : reach</td> <td class="xl69">Site 1</td> <td class="xl67">F5/F2</td> </tr> <tr style="height: 15pt;" height="20"> <td class="xl70" style="height: 15pt;" height="20">13</td> <td class="xl66">Aug-07</td> <td class="xl65">Male: 18-24</td> <td class="xl65">Sports Category</td> <td class="xl65">calculated metric : reach</td> <td class="xl69">Site 1</td> <td class="xl67">F6/F3</td> </tr> <tr style="height: 15pt;" height="20"> <td class="xl70" style="height: 15pt;" height="20">14</td> <td class="xl66">Sep-07</td> <td class="xl65">Male: 18-24</td> <td class="xl65">Sports Category</td> <td class="xl65">calculated metric : reach</td> <td class="xl69">Site1</td> <td class="xl67">F7/F4</td> </tr> <tr style="height: 15pt;" height="20"> <td class="xl70" style="height: 15pt;" height="20">15</td> <td class="xl66">Jul-07</td> <td class="xl65">Male: 18-24</td> <td class="xl65">Sports Category</td> <td class="xl65">calculated metric : reach</td> <td class="xl69">Site 2</td> <td class="xl67">F9/F2</td> </tr> <tr style="height: 15pt;" height="20"> <td class="xl70" style="height: 15pt;" height="20">16</td> <td class="xl66">Aug-07</td> <td class="xl65">Male: 18-24</td> <td class="xl65">Sports Category</td> <td class="xl65">calculated metric : reach</td> <td class="xl69">Site 2</td> <td class="xl67">F10/F3</td> </tr> <tr style="height: 15pt;" height="20"> <td class="xl70" style="height: 15pt;" height="20">17</td> <td class="xl66">Sep-07</td> <td class="xl65">Male: 18-24</td> <td class="xl65">Sports Category</td> <td class="xl65">calculated metric : reach</td> <td class="xl69">Site 2</td> <td class="xl67">F11/F4</td> </tr> </tbody></table>
Code:
Sub DATA()
Application.ScreenUpdating = False
Sheets("Competitive Raw Data").Cells.Delete Shift:=xlUp
For MY_SHEETS = 10 To 14
With Sheets(MY_SHEETS)
MY_DEMOGRAPHIC = .Range("F4").Value
MY_MEDIA = .Range("F5").Value
For MY_ROWS = 10 To .Range("C65536").End(xlUp).Row
If IsEmpty(.Range("D" & MY_ROWS)) Then
MY_METRIC = .Range("C" & MY_ROWS).Value
Else
For MY_MONTHS = 4 To .Range("IV9").End(xlToLeft).Column
MY_MONTH = .Cells(9, MY_MONTHS).Value
MY_HEADING = .Cells(MY_ROWS, 3).Value
MY_VALUE = .Cells(MY_ROWS, MY_MONTHS).Value
With Sheets("Competitive Raw Data")
.Range("A65536").End(xlUp).Offset(1, 0).Value = MY_MONTH
.Range("B65536").End(xlUp).Offset(1, 0).Value = MY_DEMOGRAPHIC
.Range("C65536").End(xlUp).Offset(1, 0).Value = MY_MEDIA
.Range("D65536").End(xlUp).Offset(1, 0).Value = MY_METRIC
.Range("E65536").End(xlUp).Offset(1, 0).Value = MY_HEADING
.Range("F65536").End(xlUp).Offset(1, 0).Value = MY_VALUE
End With
Next MY_MONTHS
End If
Next MY_ROWS
End With
Next MY_SHEETS
With Sheets("Competitive Raw Data")
.Range("A1").Value = "Month"
.Range("B1").Value = "Demographic"
.Range("C1").Value = "Media"
.Range("D1").Value = "Metric"
.Range("E1").Value = "Property"
.Range("F1").Value = "Value"
End With
Call Top5
Application.ScreenUpdating = True
End Sub