View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
sverre sverre is offline
external usenet poster
 
Posts: 78
Default Insert a text in Column A and calculate the average from colum

Thank you Nigel.
Thank you. This works too. Its a useful program. wich I have stored in my
collection.

Nigel skrev:

Will insert formula into empty row - based on empty column A.

Sub SetAverage()
Dim lfR As Long, llR As Long
Dim lcR As Long

On Error GoTo errHandler
With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
End With
With ActiveSheet
lfR = 1
For lcR = 1 To .Cells(.Rows.Count, "B").End(xlUp).Row + 1
If Len(Trim(.Cells(lcR, 1))) = 0 Then
.Cells(lcR, 1) = .Cells(lcR - 1, 1) & "- Averages"
.Cells(lcR, 2).Formula = "=AVERAGE(B" & lfR & ":B" & lcR - 1 & ")"
.Cells(lcR, 2).Copy Destination:=.Range(.Cells(lcR, 3), .Cells(lcR,
21))
lfR = lcR + 1
End If
Next
End With

errHandler:
With Application
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
End With
End Sub

--

Regards,
Nigel




"Sverre" wrote in message
...
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