Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 78
Default Insert a text in column A and calculoate the average for every gro

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

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,520
Default Insert a text in column A and calculoate the average for every gro

Assuming that your data will not have any blank lines inbeween, the below
macro will insert a blank row between each group, insert a text in ColA with
<RangeString & "Data" and then will insert the Average formula from ColB to
Col U. Please try and feedback

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



If this post helps click Yes
---------------
Jacob Skaria


"Sverre" wrote:

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

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 78
Default Insert a text in column A and calculoate the average for every



Thank you. There are two lines with errors:
Cells(lngRow, lngCol).FormulaR1C1 = "=Average(R" & lngStartRow & "C:R" &

Cells(lngRow, lngCol).FormulaR1C1 = "=Average(R" & lngStartRow & "C:R" &
lngRow -1 & "C)"

Are the statments too long ?










Jacob Skaria skrev:

Assuming that your data will not have any blank lines inbeween, the below
macro will insert a blank row between each group, insert a text in ColA with
<RangeString & "Data" and then will insert the Average formula from ColB to
Col U. Please try and feedback

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



If this post helps click Yes
---------------
Jacob Skaria


"Sverre" wrote:

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

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,520
Default Insert a text in column A and calculoate the average for every

Try this..

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



If this post helps click Yes
---------------
Jacob Skaria


"Sverre" wrote:



Thank you. There are two lines with errors:
Cells(lngRow, lngCol).FormulaR1C1 = "=Average(R" & lngStartRow & "C:R" &

Cells(lngRow, lngCol).FormulaR1C1 = "=Average(R" & lngStartRow & "C:R" &
lngRow -1 & "C)"

Are the statments too long ?










Jacob Skaria skrev:

Assuming that your data will not have any blank lines inbeween, the below
macro will insert a blank row between each group, insert a text in ColA with
<RangeString & "Data" and then will insert the Average formula from ColB to
Col U. Please try and feedback

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



If this post helps click Yes
---------------
Jacob Skaria


"Sverre" wrote:

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

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 78
Default Insert a text in column A and calculoate the average for every

It works perfectly-Thank you very much !!!!!!!!!!!

Jacob Skaria skrev:

Try this..

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



If this post helps click Yes
---------------
Jacob Skaria


"Sverre" wrote:



Thank you. There are two lines with errors:
Cells(lngRow, lngCol).FormulaR1C1 = "=Average(R" & lngStartRow & "C:R" &

Cells(lngRow, lngCol).FormulaR1C1 = "=Average(R" & lngStartRow & "C:R" &
lngRow -1 & "C)"

Are the statments too long ?










Jacob Skaria skrev:

Assuming that your data will not have any blank lines inbeween, the below
macro will insert a blank row between each group, insert a text in ColA with
<RangeString & "Data" and then will insert the Average formula from ColB to
Col U. Please try and feedback

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



If this post helps click Yes
---------------
Jacob Skaria


"Sverre" wrote:

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert cell text every 5 rows in a column Mike Mike Excel Discussion (Misc queries) 9 September 16th 10 09:53 AM
Request for VB to do something simple (insert text in a column ofcells) David Nebenzahl Excel Discussion (Misc queries) 5 November 21st 07 04:24 AM
when the column text is different, how to insert one row below eac Greensky Young Excel Worksheet Functions 5 April 24th 07 04:32 PM
How to insert text in one column and populate numbers in another Alice Excel Worksheet Functions 0 March 28th 06 07:27 PM
how insert same text in empty cells in column (10000 rows) bromptongadgets Excel Worksheet Functions 1 December 11th 05 03:13 PM


All times are GMT +1. The time now is 09:35 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"