Hi, I'm new to VBA and have spent today struggling through a relatively simple piece of code.
I have a table with M columns and 200+ rows. They have all been grouped into categories (using an earlier macro) and one blank row has been inserted between each group.
I've come up with this, which works, but is there a simpler way to do it, rather than repeating it 11 times for each column then 7 times for each category??
I'd really appreciate any help!
I have a table with M columns and 200+ rows. They have all been grouped into categories (using an earlier macro) and one blank row has been inserted between each group.
I've come up with this, which works, but is there a simpler way to do it, rather than repeating it 11 times for each column then 7 times for each category??
I'd really appreciate any help!
PHP:
Dim AnaEndRow As Integer
Dim AnaStartRow As Integer
Dim AnaAverage1 As Double
Dim AnaAverage2 As Double
Dim AnaAverage3 As Double
Dim AnaAverage4 As Double
Dim AnaAverage6 As Double
Dim AnaAverage7 As Double
Dim AnaAverage8 As Double
Dim AnaAverage9 As Double
Dim AnaAverage10 As Double
Dim AnaAverage11 As Double
Dim AnaAverage12 As Double
Dim Cell As Range
Dim Total1 As Double
Dim Total2 As Double
Dim Total3 As Double
Dim Total4 As Double
Dim Total6 As Double
Dim Total7 As Double
Dim Total8 As Double
Dim Total9 As Double
Dim Total10 As Double
Dim Total11 As Double
Dim Total12 As Double
Dim Count As Integer
Sheets("Types").Activate
AnaStartRow = Range("B:B").Find(what:="Annual", after:=Range("B1"), LookIn:=xlValues, Lookat:=xlWhole, searchorder:=xlByColumns).Row
AnaEndRow = Range("B:B").Find(what:="Annual", after:=Range("B1"), LookIn:=xlValues, Lookat:=xlWhole, searchorder:=xlByColumns, searchdirection:=xlPrevious).Row
For Each Cell In Range("C3:C1000")
If Cell.Row >= AnaStartRow And Cell.Row < AnaEndRow Then
Total1 = Total1 + Cell.Value
Count = Count + 1
End If
Next Cell
AnaAverage1 = Total1 / Count
Range("C" & AnaEndRow).Value = AnaAverage1
For Each Cell In Range("D3:D1000")
If Cell.Row >= AnaStartRow And Cell.Row < AnaEndRow Then
Total2 = Total2 + Cell.Value
End If
Next Cell
AnaAverage2 = Total2 / Count
Range("D" & AnaEndRow).Value = AnaAverage2
For Each Cell In Range("E3:E1000")
If Cell.Row >= AnaStartRow And Cell.Row < AnaEndRow Then
Total3 = Total3 + Cell.Value
End If
Next Cell
AnaAverage3 = Total3 / Count
Range("E" & AnaEndRow).Value = AnaAverage3
etc.