Good morning,
I hope someone can assist me with this (btw, if this is a duplicate of a
post I just made, apologies... my IE browser said that an issue had occured,
and I don't believe it did post)
I have the following code to insert a line after groups (of 2 rows usually*):
Sub test()
firstrow = 2 'set to your first data row
lastrow = 300 'set or caclulate lat data row
datecolumn = 9 'assign as necessary
checkrow = firstrow
While checkrow < lastrow
If Cells(checkrow, datecolumn) <> Cells(checkrow + 1, datecolumn) Then
Rows(checkrow + 1).EntireRow.Insert
checkrow = checkrow + 2
lastrow = lastrow + 1
Else: checkrow = checkrow + 1
End If
Wend
End Sub
However, what I need now (and can't work out at all), is for the following
to occur within that inserted blank line:
in column 6 - sum of grouped rows above
in column 8 - sum of grouped rows above
in column 9 - copy text that is in row above
Example:
1 2 3 4 5 6 7 8 9
x x x x x 1 x 2 y
x x x x x 3 x 4 y
4 6 y
Please if someone can help me add this extra requirement into my code (or
have a new module to do this) I would be so grateful.
Thanks in advance,
Kind regards,
Paul
|
|
0
|
|
|
|
Reply
|
Utf
|
1/19/2010 11:38:01 AM |
|
firstrow = 2 'set to your first data row
datecolumn = 9 'assign as necessary
lastrow = Cells(Rows.Count, datecolumn).End(xlUp).Row 'set or caclulate
lat data row
checkrow = firstrow
startrow = firstrow
While checkrow < lastrow + 1
If Cells(checkrow, datecolumn) <> Cells(checkrow + 1, datecolumn)
Then
Rows(checkrow + 1).EntireRow.Insert
Cells(checkrow + 1, 6).FormulaR1C1 = "=SUM(R" & startrow &
"C:R[-1]C)"
Cells(checkrow + 1, 8).FormulaR1C1 = "=SUM(R" & startrow &
"C:R[-1]C)"
Cells(checkrow + 1, datecolumn).Value = Cells(checkrow,
datecolumn).Value
checkrow = checkrow + 2
startrow = checkrow
lastrow = lastrow + 1
Else
checkrow = checkrow + 1
End If
Wend
HTH
Bob
"PVANS" <PVANS@discussions.microsoft.com> wrote in message
news:795695D5-B844-44E6-B562-AD4E3E8B450B@microsoft.com...
> Good morning,
>
> I hope someone can assist me with this (btw, if this is a duplicate of a
> post I just made, apologies... my IE browser said that an issue had
> occured,
> and I don't believe it did post)
>
> I have the following code to insert a line after groups (of 2 rows
> usually*):
> Sub test()
> firstrow = 2 'set to your first data row
> lastrow = 300 'set or caclulate lat data row
> datecolumn = 9 'assign as necessary
> checkrow = firstrow
> While checkrow < lastrow
> If Cells(checkrow, datecolumn) <> Cells(checkrow + 1, datecolumn) Then
> Rows(checkrow + 1).EntireRow.Insert
> checkrow = checkrow + 2
> lastrow = lastrow + 1
> Else: checkrow = checkrow + 1
> End If
> Wend
> End Sub
>
> However, what I need now (and can't work out at all), is for the following
> to occur within that inserted blank line:
> in column 6 - sum of grouped rows above
> in column 8 - sum of grouped rows above
> in column 9 - copy text that is in row above
>
> Example:
> 1 2 3 4 5 6 7 8 9
> x x x x x 1 x 2 y
> x x x x x 3 x 4 y
> 4 6 y
>
> Please if someone can help me add this extra requirement into my code (or
> have a new module to do this) I would be so grateful.
>
> Thanks in advance,
>
> Kind regards,
> Paul
|
|
0
|
|
|
|
Reply
|
Bob
|
1/19/2010 11:52:16 AM
|
|
See if this helps
Sub test()
FirstRow = 2 'set to your first data row
lastrow = 300 'set or caclulate lat data row
datecolumn = 9 'assign as necessary
checkrow = FirstRow
While checkrow < lastrow
If Cells(checkrow, datecolumn) <> Cells(checkrow + 1, datecolumn) Then
Rows(checkrow + 1).EntireRow.Insert
For col = 1 To (datecolumn - 1)
Set Sumrange = Range(Cells(FirstRow, col), Cells(checkrow, col))
MySum = WorksheetFunction.Sum(Sumrange)
If MySum <> 0 Then
Cells(checkrow + 1, col) = MySum
End If
Next col
checkrow = checkrow + 2
lastrow = lastrow + 1
Else: checkrow = checkrow + 1
End If
Wend
End Sub
--
joel
------------------------------------------------------------------------
joel's Profile: 229
View this thread: http://www.thecodecage.com/forumz/showthread.php?t=171296
[url="http://www.thecodecage.com"]Microsoft Office Help[/url]
|
|
0
|
|
|
|
Reply
|
joel
|
1/19/2010 12:11:42 PM
|
|
Modified your code to suit the requirement....
Sub test()
firstrow = 2 'set to your first data row
lastrow = 300 'set or caclulate lat data row
datecolumn = 9 'assign as necessary
checkrow = firstrow
While checkrow < lastrow
If Cells(checkrow, datecolumn) <> Cells(checkrow + 1, datecolumn) Then
Rows(checkrow + 1).EntireRow.Insert
Range("F" & checkrow + 1).Formula = _
"=SUM(F" & firstrow & ":F" & checkrow & ")"
Range("H" & checkrow + 1).Formula = _
"=SUM(H" & firstrow & ":H" & checkrow & ")"
Range("I" & checkrow + 1) = Range("I" & checkrow)
firstrow = checkrow + 2
checkrow = checkrow + 2
lastrow = lastrow + 1
Else: checkrow = checkrow + 1
End If
Wend
End Sub
--
Jacob
"PVANS" wrote:
> Good morning,
>
> I hope someone can assist me with this (btw, if this is a duplicate of a
> post I just made, apologies... my IE browser said that an issue had occured,
> and I don't believe it did post)
>
> I have the following code to insert a line after groups (of 2 rows usually*):
> Sub test()
> firstrow = 2 'set to your first data row
> lastrow = 300 'set or caclulate lat data row
> datecolumn = 9 'assign as necessary
> checkrow = firstrow
> While checkrow < lastrow
> If Cells(checkrow, datecolumn) <> Cells(checkrow + 1, datecolumn) Then
> Rows(checkrow + 1).EntireRow.Insert
> checkrow = checkrow + 2
> lastrow = lastrow + 1
> Else: checkrow = checkrow + 1
> End If
> Wend
> End Sub
>
> However, what I need now (and can't work out at all), is for the following
> to occur within that inserted blank line:
> in column 6 - sum of grouped rows above
> in column 8 - sum of grouped rows above
> in column 9 - copy text that is in row above
>
> Example:
> 1 2 3 4 5 6 7 8 9
> x x x x x 1 x 2 y
> x x x x x 3 x 4 y
> 4 6 y
>
> Please if someone can help me add this extra requirement into my code (or
> have a new module to do this) I would be so grateful.
>
> Thanks in advance,
>
> Kind regards,
> Paul
|
|
0
|
|
|
|
Reply
|
Utf
|
1/19/2010 12:23:01 PM
|
|
Jacob,
thank you so much - I really appreciate it. It works perfectly
Thanks Bob and Joel for your input as well, I appreciate the assistance
regards
"Jacob Skaria" wrote:
> Modified your code to suit the requirement....
>
> Sub test()
> firstrow = 2 'set to your first data row
> lastrow = 300 'set or caclulate lat data row
> datecolumn = 9 'assign as necessary
> checkrow = firstrow
> While checkrow < lastrow
> If Cells(checkrow, datecolumn) <> Cells(checkrow + 1, datecolumn) Then
> Rows(checkrow + 1).EntireRow.Insert
> Range("F" & checkrow + 1).Formula = _
> "=SUM(F" & firstrow & ":F" & checkrow & ")"
> Range("H" & checkrow + 1).Formula = _
> "=SUM(H" & firstrow & ":H" & checkrow & ")"
> Range("I" & checkrow + 1) = Range("I" & checkrow)
> firstrow = checkrow + 2
> checkrow = checkrow + 2
> lastrow = lastrow + 1
> Else: checkrow = checkrow + 1
> End If
> Wend
> End Sub
>
> --
> Jacob
>
>
> "PVANS" wrote:
>
> > Good morning,
> >
> > I hope someone can assist me with this (btw, if this is a duplicate of a
> > post I just made, apologies... my IE browser said that an issue had occured,
> > and I don't believe it did post)
> >
> > I have the following code to insert a line after groups (of 2 rows usually*):
> > Sub test()
> > firstrow = 2 'set to your first data row
> > lastrow = 300 'set or caclulate lat data row
> > datecolumn = 9 'assign as necessary
> > checkrow = firstrow
> > While checkrow < lastrow
> > If Cells(checkrow, datecolumn) <> Cells(checkrow + 1, datecolumn) Then
> > Rows(checkrow + 1).EntireRow.Insert
> > checkrow = checkrow + 2
> > lastrow = lastrow + 1
> > Else: checkrow = checkrow + 1
> > End If
> > Wend
> > End Sub
> >
> > However, what I need now (and can't work out at all), is for the following
> > to occur within that inserted blank line:
> > in column 6 - sum of grouped rows above
> > in column 8 - sum of grouped rows above
> > in column 9 - copy text that is in row above
> >
> > Example:
> > 1 2 3 4 5 6 7 8 9
> > x x x x x 1 x 2 y
> > x x x x x 3 x 4 y
> > 4 6 y
> >
> > Please if someone can help me add this extra requirement into my code (or
> > have a new module to do this) I would be so grateful.
> >
> > Thanks in advance,
> >
> > Kind regards,
> > Paul
|
|
0
|
|
|
|
Reply
|
Utf
|
1/19/2010 1:57:01 PM
|
|
|
4 Replies
439 Views
(page loaded in 0.096 seconds)
Similiar Articles: VBA Code to calculate SUM and COPY&PASTE cell value in inserted li ...Good morning, I hope someone can assist me with this (btw, if this is a duplicate of a post I just made, apologies... my IE browser said that an ... VBA code to find first blank cell in a column and activate it ...VBA Code to calculate SUM and COPY&PASTE cell value in ..... that inserted blank line: in column 6 ... set to your first data ... Sum The Values In Cells ... VBA: Paste in a range - microsoft.public.excel.programming ...VBA Code to calculate SUM and COPY&PASTE cell value in ..... EntireRow.Insert For col = 1 To ... Vba Code To Copy/paste On Inserted Rows - I ... or with vba code, this ... VBA: Copy a date and paste as text - microsoft.public.excel ...... to calculate SUM and COPY&PASTE cell value in ..... rows above in column 8 - sum of grouped rows above in column 9 - copy text ... Vba Code To Copy/paste On Inserted ... how can i make a line inserted in excel be straight - microsoft ...VBA Code to calculate SUM and COPY&PASTE cell value in inserted li ..... work out at all), is for the following to occur within that inserted blank line ... MAX Function in VBE - microsoft.public.excel.programming ...... value of a VBA variable inside a cell - microsoft.public ... How can I nest MAX function inside ... VBA Code to calculate SUM and COPY&PASTE cell value in inserted ... Multiple Numbers in a cell - microsoft.public.excel.worksheet ...... to columns, transpose the data, then copy and paste the ... the top menu, select Insert/Module and paste the code ... I need to distribute it into equal values in 10 cells. Display required succeeding cells value if a cell value A1 is capt ...... the find method since the VBA help code uses ... cells value if a cell value A1 is capt ... I inserted a new ... Excel - Find Next Blank Cell And Paste Copied Values Excel Vba ... If the cell is not empty, then... - microsoft.public.excel ...... cells for same values via VBA ... sum_range) based on the blank cells in ... I need a macro to select and copy all non-blank cells in Sheet1, then paste ... ... the code ... formula to hide a row in excel 2007 - microsoft.public.excel.misc ...... the formula to unhide row 27 if the value of cell ... Right click your sheet tab, view code and paste ... You send a copy of this message on an inserted sheet 2. VBA Code to calculate SUM and COPY&PASTE cell value in inserted li ...Excel - VBA Code to calculate SUM and COPY&PASTE cell value in inserted li [SOLVED] VBA Code to calculate SUM and COPY&PASTE cell value in ...Re: VBA Code to calculate SUM and COPY&PASTE cell value in inserted li VBA Code to calculate SUM and COPY&PASTE cell value in inserted li ...Good morning, I hope someone can assist me with this (btw, if this is a duplicate of a post I just made, apologies... my IE browser said that an ... Excel - Vba Find Formula & Copy Output To Adjacent Cell - Hello I ...Vba Find Formula & Copy Output To Adjacent Cell - Hello I am in need of a bit of VBA code that ... gives a sum. 3. Most cells are ... cant also copy and paste as especial (values ... Move or copy cells and cell contents - Excel - Office.comCopy cell values, cell formats, or formulas only. When you paste copied data, you can do any of ... cell B8 contains the formula =SUM(B1:B7). If you copy the formula to cell ... 7/17/2012 4:42:46 AM
|