PC Review


Reply
Thread Tools Rate Thread

copy and paste a row

 
 
daisy2008
Guest
Posts: n/a
 
      22nd Dec 2008
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
 
 
 
 
Per Jessen
Guest
Posts: n/a
 
      22nd Dec 2008
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 <daisy2...@discussions.microsoft.com>
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
 
Rick Rothstein
Guest
Posts: n/a
 
      22nd Dec 2008
Your company has the help files locked out? That seems to me like a crazy
thing for them to have done. Here is a link to the online help files...

http://msdn.microsoft.com/en-us/library/aa272268(office.11).aspx

Not as convenient as being able to hit F1, but it should be of some help to
you.

--
Rick (MVP - Excel)


"daisy2008" <(E-Mail Removed)> wrote in message
news:50269262-98E4-4D5A-90B9-(E-Mail Removed)...
>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
 
daisy2008
Guest
Posts: n/a
 
      22nd Dec 2008
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 <daisy2...@discussions.microsoft.com>
> 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
Guest
Posts: n/a
 
      22nd Dec 2008
Might be easier to use
data>filter>autofilter>filter on the column with the months for the
month>copy/paste

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"daisy2008" <(E-Mail Removed)> wrote in message
news:B360C012-7C56-4E0A-BA06-(E-Mail Removed)...
> 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 <daisy2...@discussions.microsoft.com>
>> 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
 
Rick Rothstein
Guest
Posts: n/a
 
      22nd Dec 2008
Still not enough detail. Is the ?? the month for the date in the ActiveCell
(your original code was referencing the ActiveCell)? Are there more than one
year's worth of data on the sheet (meaning the same month for different
years is possible in your data)? Here is a macro that assumes the answer was
"yes" to my first question...

Sub CopyRows()
Dim R As Range
Dim Combo As Range
For Each R In Worksheets("Sheet1").UsedRange.Rows
If Month(Cells(R.Row, "C")) = Month(ActiveCell.Value) Then
If Combo Is Nothing Then
Set Combo = R.EntireRow
Else
Set Combo = Union(Combo, R.EntireRow)
End If
End If
Next
Combo.Copy Worksheets("Sheet6").Range("A3")
End Sub

--
Rick (MVP - Excel)


"daisy2008" <(E-Mail Removed)> wrote in message
news:B360C012-7C56-4E0A-BA06-(E-Mail Removed)...
> 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 <daisy2...@discussions.microsoft.com>
>> 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
 
daisy2008
Guest
Posts: n/a
 
      22nd Dec 2008
Yes, it is crazy but what can you do. Thank you so much for the link that
will come in handy.

Do you have any ideas why this code is not working? I'm just learning. Per
Jessen stated I needed a next statement to continue the loop. So right if I
take that line out it will copy the first row it finds. I need it to copy
all of the rows that has that value. Any ideas?

Daisy

"Rick Rothstein" wrote:

> Your company has the help files locked out? That seems to me like a crazy
> thing for them to have done. Here is a link to the online help files...
>
> http://msdn.microsoft.com/en-us/library/aa272268(office.11).aspx
>
> Not as convenient as being able to hit F1, but it should be of some help to
> you.
>
> --
> Rick (MVP - Excel)
>
>
> "daisy2008" <(E-Mail Removed)> wrote in message
> news:50269262-98E4-4D5A-90B9-(E-Mail Removed)...
> >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
 
daisy2008
Guest
Posts: n/a
 
      22nd Dec 2008
Yes that is correct the month is the active cell in sheet 3. No there will
only be one year.

I put that code in and I'm getting a mismatch error now. What am I doing
wrong?

"Rick Rothstein" wrote:

> Still not enough detail. Is the ?? the month for the date in the ActiveCell
> (your original code was referencing the ActiveCell)? Are there more than one
> year's worth of data on the sheet (meaning the same month for different
> years is possible in your data)? Here is a macro that assumes the answer was
> "yes" to my first question...
>
> Sub CopyRows()
> Dim R As Range
> Dim Combo As Range
> For Each R In Worksheets("Sheet1").UsedRange.Rows
> If Month(Cells(R.Row, "C")) = Month(ActiveCell.Value) Then
> If Combo Is Nothing Then
> Set Combo = R.EntireRow
> Else
> Set Combo = Union(Combo, R.EntireRow)
> End If
> End If
> Next
> Combo.Copy Worksheets("Sheet6").Range("A3")
> End Sub
>
> --
> Rick (MVP - Excel)
>
>
> "daisy2008" <(E-Mail Removed)> wrote in message
> news:B360C012-7C56-4E0A-BA06-(E-Mail Removed)...
> > 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 <daisy2...@discussions.microsoft.com>
> >> 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
 
daisy2008
Guest
Posts: n/a
 
      22nd Dec 2008
Hi Don,

No that will not work for me. I have users that know nothing about excel
and the easier I can make it on them the better but thank you.

Daisy

"Don Guillett" wrote:

> Might be easier to use
> data>filter>autofilter>filter on the column with the months for the
> month>copy/paste
>
> --
> Don Guillett
> Microsoft MVP Excel
> SalesAid Software
> (E-Mail Removed)
> "daisy2008" <(E-Mail Removed)> wrote in message
> news:B360C012-7C56-4E0A-BA06-(E-Mail Removed)...
> > 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 <daisy2...@discussions.microsoft.com>
> >> 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
 
Rick Rothstein
Guest
Posts: n/a
 
      22nd Dec 2008
Sorry, I left a test code reference in my posted code instead of the
reference you wanted. See if this works for you...

Sub CopyRows()
Dim R As Range
Dim Combo As Range
For Each R In Worksheets("Sheet1").UsedRange.Rows
If Month(Cells(R.Row, "C")) = Month(ActiveCell.Value) Then
If Combo Is Nothing Then
Set Combo = R.EntireRow
Else
Set Combo = Union(Combo, R.EntireRow)
End If
End If
Next
Combo.Copy Worksheets("Sheet2").Range("A3")
End Sub

If this code still doesn't work, then it probably means your ActiveCell
doesn't have a date in it. If that is the case, then what is in the
ActiveCell... the month name or month number?

--
Rick (MVP - Excel)


"daisy2008" <(E-Mail Removed)> wrote in message
news:9F214386-F548-481F-BA3F-(E-Mail Removed)...
> Yes that is correct the month is the active cell in sheet 3. No there
> will
> only be one year.
>
> I put that code in and I'm getting a mismatch error now. What am I
> doing
> wrong?
>
> "Rick Rothstein" wrote:
>
>> Still not enough detail. Is the ?? the month for the date in the
>> ActiveCell
>> (your original code was referencing the ActiveCell)? Are there more than
>> one
>> year's worth of data on the sheet (meaning the same month for different
>> years is possible in your data)? Here is a macro that assumes the answer
>> was
>> "yes" to my first question...
>>
>> Sub CopyRows()
>> Dim R As Range
>> Dim Combo As Range
>> For Each R In Worksheets("Sheet1").UsedRange.Rows
>> If Month(Cells(R.Row, "C")) = Month(ActiveCell.Value) Then
>> If Combo Is Nothing Then
>> Set Combo = R.EntireRow
>> Else
>> Set Combo = Union(Combo, R.EntireRow)
>> End If
>> End If
>> Next
>> Combo.Copy Worksheets("Sheet6").Range("A3")
>> End Sub
>>
>> --
>> Rick (MVP - Excel)
>>
>>
>> "daisy2008" <(E-Mail Removed)> wrote in message
>> news:B360C012-7C56-4E0A-BA06-(E-Mail Removed)...
>> > 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 <daisy2...@discussions.microsoft.com>
>> >> 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
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I get copy/paste to copy/paste text and not the whole page =?Utf-8?B?Q2Fyb2wgSi4=?= Microsoft Word Document Management 1 6th May 2005 09:03 PM
Copy and Paste macro needs to paste to a changing cell reference =?Utf-8?B?bG91bG91?= Microsoft Excel Programming 0 24th Feb 2005 10:29 AM
Copy & Paste Object without using the Excel Copy Paste functions =?Utf-8?B?R2Fueg==?= Microsoft Excel New Users 0 10th Mar 2004 07:06 AM
Copy & Paste Object without using the Excel Copy Paste functions =?Utf-8?B?R2Fueg==?= Microsoft Excel Misc 0 10th Mar 2004 07:06 AM
Re: Copy/Paste in Excel prints highlighted cells and does not paste Dave Peterson Microsoft Excel Misc 0 30th Jul 2003 11:08 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:15 AM.