Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default Insert and Copy Data to new Workbook Row

Apologies for the re-post but I originally posted this request into the wrong
forum!

I need to insert a new row into a workbook where a character in Column "A" =
"D" and then copy the row which is two rows above into the new inserted row.

I can insert the row ok with the following code;

Sub Add_Rows()

Dim lastrow As Long, i As Long

lastrow = Cells(Rows.Count, 1).End(xlUp).Row
For i = lastrow To 2 Step -1
If Cells(i, 1) = "D" Then
Rows(i).Insert
End If
Next
End Sub

but what I can't do is copy the cells in 2 rows above this newly inserted row?

..

I have been searching and reading numerous threads and links but to no avail.

Can anyone assist?, i am using 2003.

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200604/1
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 718
Default Insert and Copy Data to new Workbook Row

Sub Add_Rows()

Dim lastrow As Long, i As Long

lastrow = Cells(Rows.Count, 1).End(xlUp).Row
For i = lastrow To 2 Step -1
If Cells(i, 1) = "D" Then
Rows(i).Insert
Rows(i - 2).Copy Rows(i)
End If
Next
End Sub

HTH
--
AP

"Ozzie via OfficeKB.com" <u18021@uwe a écrit dans le message de
news:5f5b6d83af8d8@uwe...
Apologies for the re-post but I originally posted this request into the

wrong
forum!

I need to insert a new row into a workbook where a character in Column "A"

=
"D" and then copy the row which is two rows above into the new inserted

row.

I can insert the row ok with the following code;

Sub Add_Rows()

Dim lastrow As Long, i As Long

lastrow = Cells(Rows.Count, 1).End(xlUp).Row
For i = lastrow To 2 Step -1
If Cells(i, 1) = "D" Then
Rows(i).Insert
End If
Next
End Sub

but what I can't do is copy the cells in 2 rows above this newly inserted

row?

.

I have been searching and reading numerous threads and links but to no

avail.

Can anyone assist?, i am using 2003.

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200604/1



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default Insert and Copy Data to new Workbook Row

Hi Ardus,

Cheers for your speedy response, unfortunately though the code isn't working
properly.

I think the problem is that the code appears to copy from bottom up and not
top down as is needed, apologies for not being clearer.

Regards

David


Ardus Petus wrote:
Sub Add_Rows()

Dim lastrow As Long, i As Long

lastrow = Cells(Rows.Count, 1).End(xlUp).Row
For i = lastrow To 2 Step -1
If Cells(i, 1) = "D" Then
Rows(i).Insert
Rows(i - 2).Copy Rows(i)
End If
Next
End Sub

HTH
--
AP

Apologies for the re-post but I originally posted this request into the wrong
forum!

[quoted text clipped - 23 lines]

Can anyone assist?, i am using 2003.


--
Message posted via http://www.officekb.com
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Insert and Copy Data to new Workbook Row

Maybe the other thread's reply will work.

"Ozzie via OfficeKB.com" wrote:

Apologies for the re-post but I originally posted this request into the wrong
forum!

I need to insert a new row into a workbook where a character in Column "A" =
"D" and then copy the row which is two rows above into the new inserted row.

I can insert the row ok with the following code;

Sub Add_Rows()

Dim lastrow As Long, i As Long

lastrow = Cells(Rows.Count, 1).End(xlUp).Row
For i = lastrow To 2 Step -1
If Cells(i, 1) = "D" Then
Rows(i).Insert
End If
Next
End Sub

but what I can't do is copy the cells in 2 rows above this newly inserted row?

.

I have been searching and reading numerous threads and links but to no avail.

Can anyone assist?, i am using 2003.

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200604/1


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default Insert and Copy Data to new Workbook Row

Hi Dave,

Just tried your code but like the previous post, both sets of code work from
bottom up? and I need top down.

Cheers

David

Dave Peterson wrote:
Maybe the other thread's reply will work.

Apologies for the re-post but I originally posted this request into the wrong
forum!

[quoted text clipped - 23 lines]

Can anyone assist?, i am using 2003.



--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200604/1


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default Insert and Copy Data to new Workbook Row

Dave is the problem my original piece of code which is making the copying of
the rows work from bottom up?;

lastrow = Cells(Rows.Count, 1).End(xlUp).Row
For i = lastrow To 2 Step -1




Dave Peterson wrote:
Maybe the other thread's reply will work.

Apologies for the re-post but I originally posted this request into the wrong
forum!

[quoted text clipped - 23 lines]

Can anyone assist?, i am using 2003.



--
Message posted via http://www.officekb.com
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Insert and Copy Data to new Workbook Row

It's usually lots easier to work from the bottom up.

Then you don't have to worry about what row you're on.

But the code I suggested worked fine for me. It copied the row two rows above
under the current row.

I'm not sure what you want.

"Ozzie via OfficeKB.com" wrote:

Dave is the problem my original piece of code which is making the copying of
the rows work from bottom up?;

lastrow = Cells(Rows.Count, 1).End(xlUp).Row
For i = lastrow To 2 Step -1

Dave Peterson wrote:
Maybe the other thread's reply will work.

Apologies for the re-post but I originally posted this request into the wrong
forum!

[quoted text clipped - 23 lines]

Can anyone assist?, i am using 2003.



--
Message posted via http://www.officekb.com


--

Dave Peterson
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default Insert and Copy Data to new Workbook Row

Morning Dave,

I have nearly got the code that I need, with help from Toppers, but there is
1 final bit though that hopefully you might know. My code is;

Sub InsertLines()

With Worksheets("Claim Upload")
lastrow = .Cells(Rows.Count, "A").End(xlUp).Row

For r = lastrow To 1 Step -1

If .Cells(r, "A") = "D" Then

.Cells(r, "A").Offset(1, 0).EntireRow.Insert
.Cells(r, "A").Offset(1, 0).Resize(1, 5) = Array("X", "DSINV", "C1",
"01", "cap")
.Cells(r, "A").Offset(1, 5) = Left(.Cells(r, "F"), 9)
.Cells(r, "A").Offset(1, 6) = .Cells(r, "c")
.Cells(r, "A").Offset(1, 9) = 1
.Cells(r, "A").Offset(1, 10).Resize(1, 2) = .Cells(r, "D")
.Cells(r, "A").Offset(1, 12).Resize(1, 2) = Array("no", "no")

End If
Next r

End With

End Sub

however, i need the "01" on the line below to be text and not a number format,
but am stuck on how to do it??

..Cells(r, "A").Offset(1, 0).Resize(1, 5) = Array("X", "DSINV", "C1", "01",
"cap")



Dave Peterson wrote:
It's usually lots easier to work from the bottom up.

Then you don't have to worry about what row you're on.

But the code I suggested worked fine for me. It copied the row two rows above
under the current row.

I'm not sure what you want.

Dave is the problem my original piece of code which is making the copying of
the rows work from bottom up?;

[quoted text clipped - 9 lines]

Can anyone assist?, i am using 2003.



--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200604/1
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Insert and Copy Data to new Workbook Row

You can format all 5 cells.

with .Cells(r, "A").Offset(1, 0).Resize(1, 5)
.numberformat = "@"
.value = Array("X", "DSINV", "C1", "01", "cap")
end with

or just format that one cell.

.cells(r,"A").offset(1,3).numberformat = "@"
.Cells(r, "A").Offset(1, 0).Resize(1, 5) _
= Array("X", "DSINV", "C1", "01", "cap")


"Ozzie via OfficeKB.com" wrote:

Morning Dave,

I have nearly got the code that I need, with help from Toppers, but there is
1 final bit though that hopefully you might know. My code is;

Sub InsertLines()

With Worksheets("Claim Upload")
lastrow = .Cells(Rows.Count, "A").End(xlUp).Row

For r = lastrow To 1 Step -1

If .Cells(r, "A") = "D" Then

.Cells(r, "A").Offset(1, 0).EntireRow.Insert
.Cells(r, "A").Offset(1, 0).Resize(1, 5) = Array("X", "DSINV", "C1",
"01", "cap")
.Cells(r, "A").Offset(1, 5) = Left(.Cells(r, "F"), 9)
.Cells(r, "A").Offset(1, 6) = .Cells(r, "c")
.Cells(r, "A").Offset(1, 9) = 1
.Cells(r, "A").Offset(1, 10).Resize(1, 2) = .Cells(r, "D")
.Cells(r, "A").Offset(1, 12).Resize(1, 2) = Array("no", "no")

End If
Next r

End With

End Sub

however, i need the "01" on the line below to be text and not a number format,
but am stuck on how to do it??

.Cells(r, "A").Offset(1, 0).Resize(1, 5) = Array("X", "DSINV", "C1", "01",
"cap")

Dave Peterson wrote:
It's usually lots easier to work from the bottom up.

Then you don't have to worry about what row you're on.

But the code I suggested worked fine for me. It copied the row two rows above
under the current row.

I'm not sure what you want.

Dave is the problem my original piece of code which is making the copying of
the rows work from bottom up?;

[quoted text clipped - 9 lines]

Can anyone assist?, i am using 2003.



--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200604/1


--

Dave Peterson
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
How do I copy a header to insert on multilpe sheets in a workbook Coop Excel Discussion (Misc queries) 2 July 28th 06 08:26 PM
loop through a column on a workbook copying data on each row to another workbook, then copy data back to the original workbook burl_rfc Excel Programming 1 April 1st 06 08:48 PM
create a copy of a sheet and insert it into the same workbook. Kaak[_19_] Excel Programming 0 July 15th 05 12:56 PM
create a copy of a sheet and insert it into the same workbook. funkymonkUK[_54_] Excel Programming 0 July 15th 05 12:31 PM
Insert Row & copy all formulas - shared workbook Eager2Learn[_6_] Excel Programming 1 June 10th 04 05:11 AM


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