S
Sverre
I have a sheet of 20000 rows or more. I have a grouped the sheet with one
blank line. In this blank line I want to insert a text in Column A like this;
content in the cell above+data. In addition I want to put in a formula
calculating the average for the group above from column B to column U.
CAn anyone help me with a VBA to do this. May be I have to put in two blank
lines ?
A.........................B............C
May
May
May
Maydata........Average..... Average
June
June
June
Jundata........Average ......Average
April
April
AprilData.....Average....... Average
Jacob Skaria gave me this VBA who works perfectly, but only for the first
blank line. CAn anybody help me with the rest ?
Sub InsertAverages()
Dim lngRow As Long
Dim lngCol As Long
Dim lngStartRow As Long
Dim strCurData As String
lngRow = 1
lngStartRow = lngRow
strCurData = Range("A" & lngRow)
Do While Range("A" & lngRow) <> ""
If strCurData <> Range("A" & lngRow) Then
Rows(lngRow).Insert
Range("A" & lngRow) = strCurData & " Data"
'Insert Averages from ColB to U
For lngCol = 2 To 21
Cells(lngRow, lngCol).FormulaR1C1 = "=Average(R" & lngStartRow & "C:R" &
lngRow - 1 & "C)"
Next
lngRow = lngRow + 1
lngStartRow = lngRow
strCurData = Range("A" & lngRow)
End If
lngRow = lngRow + 1
Loop
'Handle Last Range
Range("A" & lngRow) = strCurData & " Data"
For lngCol = 2 To 21
Cells(lngRow, lngCol).FormulaR1C1 = "=Average(R" & lngStartRow & "C:R" &
lngRow - 1 & "C)"
Next
End Sub
blank line. In this blank line I want to insert a text in Column A like this;
content in the cell above+data. In addition I want to put in a formula
calculating the average for the group above from column B to column U.
CAn anyone help me with a VBA to do this. May be I have to put in two blank
lines ?
A.........................B............C
May
May
May
Maydata........Average..... Average
June
June
June
Jundata........Average ......Average
April
April
AprilData.....Average....... Average
Jacob Skaria gave me this VBA who works perfectly, but only for the first
blank line. CAn anybody help me with the rest ?
Sub InsertAverages()
Dim lngRow As Long
Dim lngCol As Long
Dim lngStartRow As Long
Dim strCurData As String
lngRow = 1
lngStartRow = lngRow
strCurData = Range("A" & lngRow)
Do While Range("A" & lngRow) <> ""
If strCurData <> Range("A" & lngRow) Then
Rows(lngRow).Insert
Range("A" & lngRow) = strCurData & " Data"
'Insert Averages from ColB to U
For lngCol = 2 To 21
Cells(lngRow, lngCol).FormulaR1C1 = "=Average(R" & lngStartRow & "C:R" &
lngRow - 1 & "C)"
Next
lngRow = lngRow + 1
lngStartRow = lngRow
strCurData = Range("A" & lngRow)
End If
lngRow = lngRow + 1
Loop
'Handle Last Range
Range("A" & lngRow) = strCurData & " Data"
For lngCol = 2 To 21
Cells(lngRow, lngCol).FormulaR1C1 = "=Average(R" & lngStartRow & "C:R" &
lngRow - 1 & "C)"
Next
End Sub