Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Please help with macro

I am trying to insert a row (row 1 of sheet 2) in between any row in
sheet1 where the value in column A changes.

I have found code that inserts a blank row but I don't know how to
change it so it copies the row from sheet 2 instead. Thanks in
advance... here is the code so far.

Sub InsertRowAtChangeInValue()
Dim lRow As Long
For lRow = Cells(Cells.Rows.Count, "A").End(xlUp).Row To 2 Step
-1
If Cells(lRow, "A") < Cells(lRow - 1, "A") Then Rows
(lRow).EntireRow.Insert
Next lRow
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Please help with macro

Untested, but see if it does what you want.

Sub InsertRowAtChangeInValue()
Dim lRow As Long
For lRow = Cells(Rows.Count, "A").End(xlUp).Row To 2 Step -1
If Cells(lRow, "A") < Cells(lRow - 1, "A") Then
Sheets(2).Rows(1).Copy
Rows(lRow).Insert
Next lRow
End Sub


" wrote:

I am trying to insert a row (row 1 of sheet 2) in between any row in
sheet1 where the value in column A changes.

I have found code that inserts a blank row but I don't know how to
change it so it copies the row from sheet 2 instead. Thanks in
advance... here is the code so far.

Sub InsertRowAtChangeInValue()
Dim lRow As Long
For lRow = Cells(Cells.Rows.Count, "A").End(xlUp).Row To 2 Step
-1
If Cells(lRow, "A") < Cells(lRow - 1, "A") Then Rows
(lRow).EntireRow.Insert
Next lRow
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Please help with macro

Thanks for trying but it won't compile it says next without for
error.... I am sure it is easy to fix but I am really new at this.


Thanks,
Erik
On Nov 14, 12:15*am, JLGWhiz
wrote:
Untested, but see if it does what you want.

Sub InsertRowAtChangeInValue()
* * Dim lRow As Long
* * For lRow = *Cells(Rows.Count, "A").End(xlUp).Row To 2 *Step -1
* * * * If Cells(lRow, "A") < Cells(lRow - 1, "A") Then
* * * * Sheets(2).Rows(1).Copy
* * * * *Rows(lRow).Insert
* * Next lRow
End Sub



" wrote:
I am trying to insert a row (row 1 of sheet 2) in between any row in
sheet1 where the value in column A changes.


I have found code that inserts a blank row but I don't know how to
change it so it copies the row from sheet 2 instead. * Thanks in
advance... here is the code so far.


Sub InsertRowAtChangeInValue()
* * Dim lRow As Long
* * For lRow = *Cells(Cells.Rows.Count, "A").End(xlUp).Row To 2 *Step
-1
* * * * If Cells(lRow, "A") < Cells(lRow - 1, "A") Then Rows
(lRow).EntireRow.Insert
* * Next lRow
End Sub- Hide quoted text -


- Show quoted text -


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Please help with macro

I fixed the complie error... I just pasted it wrong but now it inserts
the formula in the right place but it creates a space in between every
line also. thanks in advance


Sub InsertRowAtChangeInValue()
Dim lRow As Long
For lRow = Cells(Cells.Rows.Count, "A").End(xlUp).Row To 2 Step -1
If Cells(lRow, "A") < Cells(lRow - 1, "A") Then Sheets(2).Rows
(1).Copy
Rows(lRow).Insert
Next lRow
End Sub

On Nov 14, 10:03*am, wrote:
Thanks for trying but it won't compile it says next without for
error.... I am sure it is easy to fix but I am really new at this.

Thanks,
Erik
On Nov 14, 12:15*am, JLGWhiz
wrote:



Untested, but see if it does what you want.


Sub InsertRowAtChangeInValue()
* * Dim lRow As Long
* * For lRow = *Cells(Rows.Count, "A").End(xlUp).Row To 2 *Step -1
* * * * If Cells(lRow, "A") < Cells(lRow - 1, "A") Then
* * * * Sheets(2).Rows(1).Copy
* * * * *Rows(lRow).Insert
* * Next lRow
End Sub


" wrote:
I am trying to insert a row (row 1 of sheet 2) in between any row in
sheet1 where the value in column A changes.


I have found code that inserts a blank row but I don't know how to
change it so it copies the row from sheet 2 instead. * Thanks in
advance... here is the code so far.


Sub InsertRowAtChangeInValue()
* * Dim lRow As Long
* * For lRow = *Cells(Cells.Rows.Count, "A").End(xlUp).Row To 2 *Step
-1
* * * * If Cells(lRow, "A") < Cells(lRow - 1, "A") Then Rows
(lRow).EntireRow.Insert
* * Next lRow
End Sub- Hide quoted text -


- Show quoted text -- Hide quoted text -


- Show quoted text -


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Please help with macro

nevermind... firgured it out... thanks for your help.

On Nov 14, 10:50*am, wrote:
I fixed the complie error... I just pasted it wrong but now it inserts
the formula in the right place but it creates a space in between every
line also. *thanks in advance

Sub InsertRowAtChangeInValue()
* * Dim lRow As Long
* * For lRow = Cells(Cells.Rows.Count, "A").End(xlUp).Row To 2 Step -1
* * * * If Cells(lRow, "A") < Cells(lRow - 1, "A") Then Sheets(2).Rows
(1).Copy
* * * * Rows(lRow).Insert
* * Next lRow
End Sub

On Nov 14, 10:03*am, wrote:



Thanks for trying but it won't compile it says next without for
error.... I am sure it is easy to fix but I am really new at this.


Thanks,
Erik
On Nov 14, 12:15*am, JLGWhiz
wrote:


Untested, but see if it does what you want.


Sub InsertRowAtChangeInValue()
* * Dim lRow As Long
* * For lRow = *Cells(Rows.Count, "A").End(xlUp).Row To 2 *Step -1
* * * * If Cells(lRow, "A") < Cells(lRow - 1, "A") Then
* * * * Sheets(2).Rows(1).Copy
* * * * *Rows(lRow).Insert
* * Next lRow
End Sub


" wrote:
I am trying to insert a row (row 1 of sheet 2) in between any row in
sheet1 where the value in column A changes.


I have found code that inserts a blank row but I don't know how to
change it so it copies the row from sheet 2 instead. * Thanks in
advance... here is the code so far.


Sub InsertRowAtChangeInValue()
* * Dim lRow As Long
* * For lRow = *Cells(Cells.Rows.Count, "A").End(xlUp).Row To 2 *Step
-1
* * * * If Cells(lRow, "A") < Cells(lRow - 1, "A") Then Rows
(lRow).EntireRow.Insert
* * Next lRow
End Sub- Hide quoted text -


- Show quoted text -- Hide quoted text -


- Show quoted text -- Hide quoted text -


- Show quoted text -




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Please help with macro

Replace the previous version with this one. You need to use a block If
statement.

Sub InsertRowAtChangeInValue()
Dim lRow As Long
For lRow = Cells(Rows.Count, "A").End(xlUp).Row To 2 Step -1
If Cells(lRow, "A") < Cells(lRow - 1, "A") Then
Sheets(2).Rows(1).Copy 'keep on separate line
Rows(lRow).Insert
End If
Next lRow
End Sub



" wrote:

I fixed the complie error... I just pasted it wrong but now it inserts
the formula in the right place but it creates a space in between every
line also. thanks in advance


Sub InsertRowAtChangeInValue()
Dim lRow As Long
For lRow = Cells(Cells.Rows.Count, "A").End(xlUp).Row To 2 Step -1
If Cells(lRow, "A") < Cells(lRow - 1, "A") Then Sheets(2).Rows
(1).Copy
Rows(lRow).Insert
Next lRow
End Sub

On Nov 14, 10:03 am, wrote:
Thanks for trying but it won't compile it says next without for
error.... I am sure it is easy to fix but I am really new at this.

Thanks,
Erik
On Nov 14, 12:15 am, JLGWhiz
wrote:



Untested, but see if it does what you want.


Sub InsertRowAtChangeInValue()
Dim lRow As Long
For lRow = Cells(Rows.Count, "A").End(xlUp).Row To 2 Step -1
If Cells(lRow, "A") < Cells(lRow - 1, "A") Then
Sheets(2).Rows(1).Copy
Rows(lRow).Insert
Next lRow
End Sub


" wrote:
I am trying to insert a row (row 1 of sheet 2) in between any row in
sheet1 where the value in column A changes.


I have found code that inserts a blank row but I don't know how to
change it so it copies the row from sheet 2 instead. Thanks in
advance... here is the code so far.


Sub InsertRowAtChangeInValue()
Dim lRow As Long
For lRow = Cells(Cells.Rows.Count, "A").End(xlUp).Row To 2 Step
-1
If Cells(lRow, "A") < Cells(lRow - 1, "A") Then Rows
(lRow).EntireRow.Insert
Next lRow
End Sub- Hide quoted text -


- Show quoted text -- Hide quoted text -


- Show quoted text -



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
Macro to copy and paste values (columns)I have a macro file built C02C04 Excel Programming 2 May 2nd 08 01:51 PM
AutoRun Macro with a delay to give user the choice to cancel the macro wanderlust Excel Programming 2 September 28th 07 04:09 PM
Macro not showing in Tools/Macro/Macros yet show up when I goto VBA editor [email protected] Excel Programming 2 March 30th 07 07:48 PM
how to count/sum by function/macro to get the number of record to do copy/paste in macro tango Excel Programming 1 October 15th 04 01:16 PM
Start Macro / Stop Macro / Restart Macro Pete[_13_] Excel Programming 2 November 21st 03 05:04 PM


All times are GMT +1. The time now is 03:00 AM.

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

About Us

"It's about Microsoft Excel"