Thread
:
copy and paste a row
View Single Post
#
5
Posted to microsoft.public.excel.programming
Don Guillett
external usenet poster
Posts: 10,124
copy and paste a row
Might be easier to use
datafilterautofilterfilter on the column with the months for the
monthcopy/paste
--
Don Guillett
Microsoft MVP Excel
SalesAid Software
"daisy2008" wrote in message
...
Hello,
I need this to copy all rows that have the month of ?? in colmun c to be
pasted to sheet 2. Sometimes it might be 3 orders placed and sometimes it
might be 10 for that month. I only need to see the desired month at a
time.
Does that help?
Daisy :)
"Per Jessen" wrote:
Hi
You have started a loop with the For i=... statement. It needs a
"Next" statement to continue the loop.
But I'm not sure the code is working as desired. If you need further
help describe in words what you desire.
Sub copy_rows()
Dim LastRow As Long, i As Long
Dim wksToSearch As Worksheet
Dim rngToSearch As Range
Dim rngFound As Range
Set wksToSearch = Sheets("Sheet1")
Set rngToSearch = wksToSearch.Columns("C")
LastRow = wksToSearch.Cells(Rows.Count, 3).End(xlUp).Row
For i = LastRow To 1 Step -1
Set rngFound = rngToSearch.Find(What:=ActiveCell, LookIn:=xlValue)
If rngFound Is Nothing Then
MsgBox "No data found"
Else
wksToSearch.Select
rngFound.EntireRow.Copy Sheets("Sheet2").Range("A3")
End If
Next
End Sub
Regards,
Per
On 22 Dec., 17:56, daisy2008
wrote:
I have played with this code but I can not make it work. Can someone
please
help me fix this? My company has the help files locked out. comes
back as
Compile error: For without Next.
Sub copy_rows()
Dim lastrow As Long, i As Long
Dim wksToSearch As Worksheet
Dim rngToSearch As Range
Dim rngFound As Range
lastrow = Sheets("Sheet1").Cells(Rows.Count, 3).End(xlUp).Row
For i = lastrow To 1 Step -1
Set wksToSearch = Sheets("Sheet1")
Set rngToSearch = wksToSearch.Columns("C")
Set rngFound = rngToSearch.Find(What:=ActiveCell, LookIn:=xlValue)
If rngFound Is Nothing Then
MsgBox "No data found"
Else
wksToSearch.Select
rngFound.EntireRow.Copy Sheets("Sheet2").Range("A3")
End If
End Sub
Reply With Quote
Don Guillett
View Public Profile
Find all posts by Don Guillett