Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Macro to copy a row, then insert shift:=x1Down

I am trying to create a macro to scan the data in Column H, when a "1" is
found, move one row up, copy that row and insert the copied row of data. I
have tried the following code, but it does not work and I cannot find an
answer in the searches I have done.

I would greatly appreciate help!

For Each Cell In Range("H:H")
If Cell.Value = "1" Then
Cell.Offset(-1, 0).Rows("1:1").EntireRow.Select
Selection.Copy.Insert Shift:=x1Down
End If
Next Cell

Lost in Alabama

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Macro to copy a row, then insert shift:=x1Down

LastRow = cells(rows.count,"H").End(xlup).Row
for i = lastrow to 1 step -1
If Cells(i + 1,1) = "1" Then
Rows(i).Copy
Rows(i + 1).Insert
End If
Next i

--
Regards,
Tom Ogilvy


"Lost in Alabama" wrote:

I am trying to create a macro to scan the data in Column H, when a "1" is
found, move one row up, copy that row and insert the copied row of data. I
have tried the following code, but it does not work and I cannot find an
answer in the searches I have done.

I would greatly appreciate help!

For Each Cell In Range("H:H")
If Cell.Value = "1" Then
Cell.Offset(-1, 0).Rows("1:1").EntireRow.Select
Selection.Copy.Insert Shift:=x1Down
End If
Next Cell

Lost in Alabama

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Macro to copy a row, then insert shift:=x1Down

Thank you, Tom, for the quick response. I tried this code, but it does not
change my data at all. Any suggestions?

Thanks,

Lost

"Tom Ogilvy" wrote:

LastRow = cells(rows.count,"H").End(xlup).Row
for i = lastrow to 1 step -1
If Cells(i + 1,1) = "1" Then
Rows(i).Copy
Rows(i + 1).Insert
End If
Next i

--
Regards,
Tom Ogilvy


"Lost in Alabama" wrote:

I am trying to create a macro to scan the data in Column H, when a "1" is
found, move one row up, copy that row and insert the copied row of data. I
have tried the following code, but it does not work and I cannot find an
answer in the searches I have done.

I would greatly appreciate help!

For Each Cell In Range("H:H")
If Cell.Value = "1" Then
Cell.Offset(-1, 0).Rows("1:1").EntireRow.Select
Selection.Copy.Insert Shift:=x1Down
End If
Next Cell

Lost in Alabama

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Macro to copy a row, then insert shift:=x1Down

Reworked the macro at the last minute and forgot to change a column
Reference from 1 to "H"
made the correction

LastRow = cells(rows.count,"H").End(xlup).Row
for i = lastrow to 1 step -1
If Cells(i + 1,"H") = "1" Then
Rows(i).Copy
Rows(i + 1).Insert
End If
Next i

--
Regards,
Tom Ogilvy



"Lost in Alabama" wrote in message
...
Thank you, Tom, for the quick response. I tried this code, but it does

not
change my data at all. Any suggestions?

Thanks,

Lost

"Tom Ogilvy" wrote:

LastRow = cells(rows.count,"H").End(xlup).Row
for i = lastrow to 1 step -1
If Cells(i + 1,1) = "1" Then
Rows(i).Copy
Rows(i + 1).Insert
End If
Next i

--
Regards,
Tom Ogilvy


"Lost in Alabama" wrote:

I am trying to create a macro to scan the data in Column H, when a "1"

is
found, move one row up, copy that row and insert the copied row of

data. I
have tried the following code, but it does not work and I cannot find

an
answer in the searches I have done.

I would greatly appreciate help!

For Each Cell In Range("H:H")
If Cell.Value = "1" Then
Cell.Offset(-1, 0).Rows("1:1").EntireRow.Select
Selection.Copy.Insert Shift:=x1Down
End If
Next Cell

Lost in Alabama



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Macro to copy a row, then insert shift:=x1Down

Tom,

You are a Blessing! This works perfectly....not sure I unnderstand it all,
but it works great!

Thanks again for sharing your knowledge.

Lost

"Tom Ogilvy" wrote:

Reworked the macro at the last minute and forgot to change a column
Reference from 1 to "H"
made the correction

LastRow = cells(rows.count,"H").End(xlup).Row
for i = lastrow to 1 step -1
If Cells(i + 1,"H") = "1" Then
Rows(i).Copy
Rows(i + 1).Insert
End If
Next i

--
Regards,
Tom Ogilvy



"Lost in Alabama" wrote in message
...
Thank you, Tom, for the quick response. I tried this code, but it does

not
change my data at all. Any suggestions?

Thanks,

Lost

"Tom Ogilvy" wrote:

LastRow = cells(rows.count,"H").End(xlup).Row
for i = lastrow to 1 step -1
If Cells(i + 1,1) = "1" Then
Rows(i).Copy
Rows(i + 1).Insert
End If
Next i

--
Regards,
Tom Ogilvy


"Lost in Alabama" wrote:

I am trying to create a macro to scan the data in Column H, when a "1"

is
found, move one row up, copy that row and insert the copied row of

data. I
have tried the following code, but it does not work and I cannot find

an
answer in the searches I have done.

I would greatly appreciate help!

For Each Cell In Range("H:H")
If Cell.Value = "1" Then
Cell.Offset(-1, 0).Rows("1:1").EntireRow.Select
Selection.Copy.Insert Shift:=x1Down
End If
Next Cell

Lost in Alabama




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
Copy Insert Macro Schwimms Excel Discussion (Misc queries) 15 February 2nd 08 12:02 PM
Macro - Insert/Copy John Britto Excel Discussion (Misc queries) 0 November 15th 07 10:01 AM
Macro to Insert and copy entire row CCrew2000 Excel Discussion (Misc queries) 3 June 26th 07 03:16 PM
MAcro to copy and insert a sheet JackR Excel Programming 7 March 20th 06 01:07 AM
copy insert macro snax500[_2_] Excel Programming 1 January 14th 05 09:17 PM


All times are GMT +1. The time now is 01:53 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"