Sunline
Well-known Member
- Joined
- Oct 6, 2007
- Messages
- 701
- Office Version
- 2016
- Platform
- Windows
Hello all , i have this macro which looks at col S (numbers) and totals a range of cells in another 3 x cols .
How its suppossed to work is in col S there are numbers from 1 to 24 , in cell S2 there is number 9 , that means there will be 9 rows containing #9 down too col S10 , next # is 8 so #8 down to S18 , next # is 14 so down too S32 and so on , there could be the same number mentioned 2 or more times , it varies over the 170,00 rows .
This macro which has stopped working then looks over too cols W,Y,AA , as with the first example in S2 being 9 will total cell range W2 too AA10 then on too next being #8 and so on .
Im hoping too get this working again after i stuffed it up , hopefully answer too go into col BO .
Also i want to do exactly the same as above but for only 1 col too total range , answer into col BO .
Sub SomeSortOfSubTotaling()
Dim WS As Worksheet
Dim LR As Long
Dim i As Long
Dim RptCount As Long
Dim MySum As Double
Dim Myrange As Range
Set WS = ActiveSheet
LR = WS.Range("S" & Rows.Count).End(xlUp).Row
i = 2
Do
If i > LR Then Exit Do
If RptCount = 0 Then
RptCount = WS.Cells(i, 20)
Set Myrange = WS.Range("W" & i & ":W" & i + RptCount - 1 _
& ",Y" & i & ":Y" & i + RptCount - 1 _
& ",AA" & i & ":AA" & i + RptCount - 1)
MySum = Application.WorksheetFunction.Sum(Myrange)
End If
WS.Cells(i, 21) = MySum
i = i + 1
RptCount = RptCount - 1
Loop
End Sub
Thankyou .
How its suppossed to work is in col S there are numbers from 1 to 24 , in cell S2 there is number 9 , that means there will be 9 rows containing #9 down too col S10 , next # is 8 so #8 down to S18 , next # is 14 so down too S32 and so on , there could be the same number mentioned 2 or more times , it varies over the 170,00 rows .
This macro which has stopped working then looks over too cols W,Y,AA , as with the first example in S2 being 9 will total cell range W2 too AA10 then on too next being #8 and so on .
Im hoping too get this working again after i stuffed it up , hopefully answer too go into col BO .
Also i want to do exactly the same as above but for only 1 col too total range , answer into col BO .
Sub SomeSortOfSubTotaling()
Dim WS As Worksheet
Dim LR As Long
Dim i As Long
Dim RptCount As Long
Dim MySum As Double
Dim Myrange As Range
Set WS = ActiveSheet
LR = WS.Range("S" & Rows.Count).End(xlUp).Row
i = 2
Do
If i > LR Then Exit Do
If RptCount = 0 Then
RptCount = WS.Cells(i, 20)
Set Myrange = WS.Range("W" & i & ":W" & i + RptCount - 1 _
& ",Y" & i & ":Y" & i + RptCount - 1 _
& ",AA" & i & ":AA" & i + RptCount - 1)
MySum = Application.WorksheetFunction.Sum(Myrange)
End If
WS.Cells(i, 21) = MySum
i = i + 1
RptCount = RptCount - 1
Loop
End Sub
Thankyou .