Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Modifying FindNext and Copy Code

I am trying modify code that Tom Ogilvy provided in a post
on 8/23/04 to basically do the same steps required in
Lolly's original post, except that I want to cut the
entire row out of the first worksheet and paste it into
a second worksheet. My problem is that I'm only getting
one out of the five records I know exist in the
spreadsheet, and I'm sure the issue is between the "Else"
and "Loop" statement. So far, the code looks like this:

Dim rng As Range, rng1 As Range
Application.Worksheets("Pivot Data").Select
Set rng = Range("PivotData").Find(What:="Funky: Ticket
Before Notify", _
LookAt:=xlWhole, LookIn:=xlValues)
If rng Is Nothing Then
MsgBox "Data Not Found"
Exit Sub
Else
Set rng1 = rng
Do While rng1.Offset(1, 0).Value = "Funky: Ticket
Before Notify"
Set rng1 = rng1.Offset(1, 0)
Loop
Range(rng, rng1).EntireRow.Copy _
Destination:=Application.Worksheets("Errors").Rang e
("A2")
End If

I'm pretty sure I'm not giving the loop the correct
instruction, but I don't know how to fix it. The text
string that I'm looking for is in Column V (Column 22).

Any help would be very much appreciated.

Thanks in advance,

Val
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Modifying FindNext and Copy Code

Try this

This example use Sheet1 and Sheet2
and this range Sheets("Sheet1").Range("A1:A100")

Change to yours

Sub Copy_To_Another_Sheet_1()
Dim FirstAddress As String
Dim MyArr As Variant
Dim Rng As Range
Dim Rcount As Long
Dim I As Long

Application.ScreenUpdating = False
'You can also use more values in the Array
'myArr = Array("@", "www")
MyArr = Array("Funky: Ticket Before Notify")

Rcount = 0
With Sheets("Sheet1").Range("A1:A100")

For I = LBound(MyArr) To UBound(MyArr)
'If you use LookIn:=xlValues it will also work with a
'formula cell that evaluates to "Funky: Ticket Before Notify"
'Note : I use xlPart in this example and not xlWhole

Set Rng = .Find(What:=MyArr(I), _
After:=.Cells(.Cells.Count), _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not Rng Is Nothing Then
FirstAddress = Rng.Address
Do
Rcount = Rcount + 1
' This example will only copy the value
Rng.EntireRow.Copy Sheets("Sheet2").Range("A" & Rcount)
Set Rng = .FindNext(Rng)
Loop While Not Rng Is Nothing And Rng.Address < FirstAddress
End If
Next I
End With
Application.ScreenUpdating = True
End Sub

--
Regards Ron de Bruin
http://www.rondebruin.nl


" wrote in message ...
I am trying modify code that Tom Ogilvy provided in a post
on 8/23/04 to basically do the same steps required in
Lolly's original post, except that I want to cut the
entire row out of the first worksheet and paste it into
a second worksheet. My problem is that I'm only getting
one out of the five records I know exist in the
spreadsheet, and I'm sure the issue is between the "Else"
and "Loop" statement. So far, the code looks like this:

Dim rng As Range, rng1 As Range
Application.Worksheets("Pivot Data").Select
Set rng = Range("PivotData").Find(What:="Funky: Ticket
Before Notify", _
LookAt:=xlWhole, LookIn:=xlValues)
If rng Is Nothing Then
MsgBox "Data Not Found"
Exit Sub
Else
Set rng1 = rng
Do While rng1.Offset(1, 0).Value = "Funky: Ticket
Before Notify"
Set rng1 = rng1.Offset(1, 0)
Loop
Range(rng, rng1).EntireRow.Copy _
Destination:=Application.Worksheets("Errors").Rang e
("A2")
End If

I'm pretty sure I'm not giving the loop the correct
instruction, but I don't know how to fix it. The text
string that I'm looking for is in Column V (Column 22).

Any help would be very much appreciated.

Thanks in advance,

Val



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Modifying FindNext and Copy Code

' This example will only copy the value
This is not true

this text is From a other example

--
Regards Ron de Bruin
http://www.rondebruin.nl


"Ron de Bruin" wrote in message ...
Try this

This example use Sheet1 and Sheet2
and this range Sheets("Sheet1").Range("A1:A100")

Change to yours

Sub Copy_To_Another_Sheet_1()
Dim FirstAddress As String
Dim MyArr As Variant
Dim Rng As Range
Dim Rcount As Long
Dim I As Long

Application.ScreenUpdating = False
'You can also use more values in the Array
'myArr = Array("@", "www")
MyArr = Array("Funky: Ticket Before Notify")

Rcount = 0
With Sheets("Sheet1").Range("A1:A100")

For I = LBound(MyArr) To UBound(MyArr)
'If you use LookIn:=xlValues it will also work with a
'formula cell that evaluates to "Funky: Ticket Before Notify"
'Note : I use xlPart in this example and not xlWhole

Set Rng = .Find(What:=MyArr(I), _
After:=.Cells(.Cells.Count), _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not Rng Is Nothing Then
FirstAddress = Rng.Address
Do
Rcount = Rcount + 1
' This example will only copy the value
Rng.EntireRow.Copy Sheets("Sheet2").Range("A" & Rcount)
Set Rng = .FindNext(Rng)
Loop While Not Rng Is Nothing And Rng.Address < FirstAddress
End If
Next I
End With
Application.ScreenUpdating = True
End Sub

--
Regards Ron de Bruin
http://www.rondebruin.nl


" wrote in message ...
I am trying modify code that Tom Ogilvy provided in a post
on 8/23/04 to basically do the same steps required in
Lolly's original post, except that I want to cut the
entire row out of the first worksheet and paste it into
a second worksheet. My problem is that I'm only getting
one out of the five records I know exist in the
spreadsheet, and I'm sure the issue is between the "Else"
and "Loop" statement. So far, the code looks like this:

Dim rng As Range, rng1 As Range
Application.Worksheets("Pivot Data").Select
Set rng = Range("PivotData").Find(What:="Funky: Ticket
Before Notify", _
LookAt:=xlWhole, LookIn:=xlValues)
If rng Is Nothing Then
MsgBox "Data Not Found"
Exit Sub
Else
Set rng1 = rng
Do While rng1.Offset(1, 0).Value = "Funky: Ticket
Before Notify"
Set rng1 = rng1.Offset(1, 0)
Loop
Range(rng, rng1).EntireRow.Copy _
Destination:=Application.Worksheets("Errors").Rang e
("A2")
End If

I'm pretty sure I'm not giving the loop the correct
instruction, but I don't know how to fix it. The text
string that I'm looking for is in Column V (Column 22).

Any help would be very much appreciated.

Thanks in advance,

Val





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Modifying FindNext and Copy Code

This would only work if you had n contiguous cells in a single column, each
containing the string

Funky: Ticket Before Notify

Usually that is not the case in a pivot tabled.

--
Regards,
Tom Ogilvy

" wrote in message
...
I am trying modify code that Tom Ogilvy provided in a post
on 8/23/04 to basically do the same steps required in
Lolly's original post, except that I want to cut the
entire row out of the first worksheet and paste it into
a second worksheet. My problem is that I'm only getting
one out of the five records I know exist in the
spreadsheet, and I'm sure the issue is between the "Else"
and "Loop" statement. So far, the code looks like this:

Dim rng As Range, rng1 As Range
Application.Worksheets("Pivot Data").Select
Set rng = Range("PivotData").Find(What:="Funky: Ticket
Before Notify", _
LookAt:=xlWhole, LookIn:=xlValues)
If rng Is Nothing Then
MsgBox "Data Not Found"
Exit Sub
Else
Set rng1 = rng
Do While rng1.Offset(1, 0).Value = "Funky: Ticket
Before Notify"
Set rng1 = rng1.Offset(1, 0)
Loop
Range(rng, rng1).EntireRow.Copy _
Destination:=Application.Worksheets("Errors").Rang e
("A2")
End If

I'm pretty sure I'm not giving the loop the correct
instruction, but I don't know how to fix it. The text
string that I'm looking for is in Column V (Column 22).

Any help would be very much appreciated.

Thanks in advance,

Val



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
FindNext and Copy Help (Urgent) Tom Ogilvy Excel Programming 3 September 15th 05 04:08 PM
FindNext and Copy Help (Urgent) Don Guillett[_4_] Excel Programming 1 August 23rd 04 07:04 PM
modifying formulas with code Rick B[_6_] Excel Programming 3 January 28th 04 02:03 PM
Need Help Modifying Code JStone0218 Excel Programming 2 January 19th 04 10:27 AM
Help modifying code BruceJ[_2_] Excel Programming 1 December 10th 03 12:52 AM


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