Sie sind auf Seite 1von 5

copy and Transfer + Content Clear Row Help VBA Excel

2003
I have the following Code in my Sheet5 but I need to have it for all rows:
Code:

If Not Intersect(Target, Range("Q:Q")) Is Nothing Then
If Target.Cells.Count = 1 Then ' stops the code looping
If LCase(Target.Value) = "yes" Then
Range("A5:P5").Copy
Sheets("Archives").Range("A" & Rows.Count).End(xlUp).Offset(1,
0).PasteSpecial lxvalue
End If
Target.EntireRow.Delete
End If
End If
So I need it for

A to P for all rows

Row starts at 5 and could go down all the way to 1000

Chnages to be done is Range("A5:P5").Copy

Error comes if I change it to Range("A:P").Copy

Please Help

Add:

The code needs to take all info on that row (A to P) and transfer to the next available "Empty"
row.

If my info is in A6 to P6 then transfer to the next available row in my sheet ("Archives") Then
Clear content of A6 to P6.

Same if I have info on A100 to P100. Find next available row then Copy info to sheet
("Archives") Then Clear content of A100 to P100.
Share
o
o
o
o
o
Reply With Quote
May 8th, 2012, 09:17 PM #2
JLGWhiz

Board Regular
Join Date
Feb 2012
Location
Florida, USA
Posts
4,089
Re: copy and Transfer + Content Clear Row Help VBA
Excel 2003
Originally Posted by Excelnoub
I have the following Code in my Sheet5 but I need to have it for all rows:




So I need it for

A to P for all rows

Row starts at 5 and could go down all the way to 1000

Chnages to be done is Range("A5:P5").Copy

Error comes if I change it to Range("A:P").Copy

Please Help

Add:

The code needs to take all info on that row (A to P) and transfer to the next available "Empty"
row.

If my info is in A6 to P6 then transfer to the next available row in my sheet ("Archives") Then
Clear content of A6 to P6.

Same if I have info on A100 to P100. Find next available row then Copy info to sheet
("Archives") Then Clear content of A100 to P100.

I think that this will take care of the copy range. But you will have to make sure that the sheet
reference is correct for the line where the lstRw variable is assigned a value, if your code is not
in sheet 1.

Code:
Dim lstRw As Long
lstRw = Sheets(1).Cells(Rows.Count, 1).End(xlUp).Row 'Change to actual sheet
If Not Intersect(Target, Range("Q:Q")) Is Nothing Then
If Target.Cells.Count = 1 Then ' stops the code looping
If LCase(Target.Value) = "yes" Then
Range("A5:P" & lstRw).Copy
Sheets("Archives").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial
Paste:=xlPasteValues
End If
Target.EntireRow.Delete
End If
End If
Code:

Also, you have a delete command for the target row. I was wondering if that would need to be
changed in view of the change in the copy range?
Share
o
o
o
o
o
Reply With Quote
May 8th, 2012, 10:16 PM #3
Excelnoub

Board Regular
Join Date
Nov 2011
Location
Canada
Posts
230
Re: copy and Transfer + Content Clear Row Help VBA
Excel 2003
It's giving me a run time error:
Code:
lstRw = Sheets(Report).Cells(Rows.Count, 1).End(xlUp).Row 'Change to actual
sheet
If Not Intersect(Target, Range("Q:Q")) Is Nothing Then
If Target.Cells.Count = 1 Then ' stops the code looping
If LCase(Target.Value) = "yes" Then
Range("A5:P" & lstRw).Copy
Sheets("Archives").Range("A" & Rows.Count).End(xlUp).Offset(1,
0).PasteSpecial Paste:=xlPasteValues
End If
Target.EntireRow.Delete
End If
End If

here is my Sheet(Report)'s full code:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim lstRw As Long

If Target.Count > 1 Then Exit Sub
If Not Intersect(Target, Range("J5:J1000")) Is Nothing Then
NumRows = Target.Value - 1
For R = 1 To NumRows
Target.Offset(1, 0).EntireRow.Insert
Next R
End If


lstRw = Sheets(Report).Cells(Rows.Count, 1).End(xlUp).Row 'Change to actual
sheet
If Not Intersect(Target, Range("Q:Q")) Is Nothing Then
If Target.Cells.Count = 1 Then ' stops the code looping
If LCase(Target.Value) = "yes" Then
Range("A5:P" & lstRw).Copy
Sheets("Archives").Range("A" & Rows.Count).End(xlUp).Offset(1,
0).PasteSpecial Paste:=xlPasteValues
End If
Target.EntireRow.Delete
End If
End If

End Sub
Share
o
o
o
o
o
Reply With Quote
May 9th, 2012, 08:03 AM #4
JLGWhiz

Board Regular
Join Date
Feb 2012
Location
Florida, USA
Posts
4,089
Re: copy and Transfer + Content Clear Row Help VBA
Excel 2003
Needed quotation marks on the sheet name.

lstRw = Sheets("Report").Cells(Rows.Count, 1).End(xlUp).Row

See if that works.