Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default Looping a loop?

I realize the following maybe a bit repatitve, but my main concern is that I
run the code and it works for finding "SA", but not "NI" or "DN". Any help
is appreciated.

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Sheets("t0983101").Select
Application.CutCopyMode = False
Range("A4").Select
Dim rngToSearch As Range
Dim wks As Worksheet
Dim rngFound As Range

Set wks = Sheets("t0983101")
Set rngToSearch = wks.Columns(5)

Set rngFound = rngToSearch.Find(what:="SA", LookIn:=xlValues,
lookat:=xlWhole)
If rngFound Is Nothing Then
Sheets("Macro Sheet").Select
End
Else
Do
rngFound.EntireRow.Cut
Sheets("SA").Select
Range("A9").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
Sheets("t0983101").Select

Set rngFound = rngToSearch.FindNext
Loop Until rngFound Is Nothing
End If
Sheets("t0983101").Select
Set wks = Sheets("t0983101")
Set rngToSearch = wks.Columns(5)
Set rngFound = rngToSearch.Find(what:="ni", LookIn:=xlValues)
If rngFound Is Nothing Then
Sheets("Macro Sheet").Select
End
Else
Do
rngFound.EntireRow.Cut
Sheets("ni").Select
Range("A9").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
Sheets("t0983101").Select

Set rngFound = rngToSearch.FindNext
Loop Until rngFound Is Nothing
End If
Set wks = Sheets("t0983101")
Set rngToSearch = wks.Columns(5)
Set rngFound = rngToSearch.Find(what:="DN", LookIn:=xlValues)
If rngFound Is Nothing Then
Sheets("Macro Sheet").Select
End
Else
Do
rngFound.EntireRow.Cut
Sheets("DN").Select
Range("A9").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
Sheets("t0983101").Select

Set rngFound = rngToSearch.FindNext
Loop Until rngFound Is Nothing
End If
end sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 595
Default Looping a loop?

John wrote:
I realize the following maybe a bit repatitve, but my main concern is
that I run the code and it works for finding "SA", but not "NI" or
"DN". Any help is appreciated.


John: When you 'Find' SA, you're looking at (LookAt) xlWhole.

Set rngFound = rngToSearch.Find(what:="SA", LookIn:=xlValues,
lookat:=xlWhole)


That argument persists between Finds unless you specifically change it.
When you search for NI, you don't specify the LookAt argument, so it remains
xlWhole. Based on what you've presented here, I would think you want that
to happen, but I don't know for sure. If NI and DN are not the whole cell,
then specify LookAt in the subsequent Finds as xlPart. I didn't see
anything else that would prevent those from being found.

Also, consider re-writing your sub as:

Sub NoTest()

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

Dim rngToSearch As Range
Dim wks As Worksheet
Dim rngFound As Range
Dim vaWhats As Variant
Dim i As Long

Set wks = Sheets("t0983101")
Set rngToSearch = wks.Columns(5)
vaWhats = Array("SA", "ni", "DS")

For i = LBound(vaWhats) To UBound(vaWhats)
Set rngFound = rngToSearch.Find(what:=vaWhats(i), _
LookIn:=xlValues, lookat:=xlWhole)

If rngFound Is Nothing Then
Sheets("Macro Sheet").Select
Exit For
Else
Do
rngFound.Copy _
Sheets(vaWhats(i)).Range("a9").End(xlDown).Offset( 1, 0)
rngFound.ClearContents
Set rngFound = rngToSearch.FindNext
Loop Until rngFound Is Nothing
End If
Next i

End Sub


--
Dick Kusleika
Excel MVP
Daily Dose of Excel
www.dicks-blog.com



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Looping a loop?

You have another similar, but different, reply at your other post.

John wrote:

I realize the following maybe a bit repatitve, but my main concern is that I
run the code and it works for finding "SA", but not "NI" or "DN". Any help
is appreciated.

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Sheets("t0983101").Select
Application.CutCopyMode = False
Range("A4").Select
Dim rngToSearch As Range
Dim wks As Worksheet
Dim rngFound As Range

Set wks = Sheets("t0983101")
Set rngToSearch = wks.Columns(5)

Set rngFound = rngToSearch.Find(what:="SA", LookIn:=xlValues,
lookat:=xlWhole)
If rngFound Is Nothing Then
Sheets("Macro Sheet").Select
End
Else
Do
rngFound.EntireRow.Cut
Sheets("SA").Select
Range("A9").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
Sheets("t0983101").Select

Set rngFound = rngToSearch.FindNext
Loop Until rngFound Is Nothing
End If
Sheets("t0983101").Select
Set wks = Sheets("t0983101")
Set rngToSearch = wks.Columns(5)
Set rngFound = rngToSearch.Find(what:="ni", LookIn:=xlValues)
If rngFound Is Nothing Then
Sheets("Macro Sheet").Select
End
Else
Do
rngFound.EntireRow.Cut
Sheets("ni").Select
Range("A9").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
Sheets("t0983101").Select

Set rngFound = rngToSearch.FindNext
Loop Until rngFound Is Nothing
End If
Set wks = Sheets("t0983101")
Set rngToSearch = wks.Columns(5)
Set rngFound = rngToSearch.Find(what:="DN", LookIn:=xlValues)
If rngFound Is Nothing Then
Sheets("Macro Sheet").Select
End
Else
Do
rngFound.EntireRow.Cut
Sheets("DN").Select
Range("A9").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
Sheets("t0983101").Select

Set rngFound = rngToSearch.FindNext
Loop Until rngFound Is Nothing
End If
end sub


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default Looping a loop?

Thanks all... thats works!

"Dave Peterson" wrote:

You have another similar, but different, reply at your other post.

John wrote:

I realize the following maybe a bit repatitve, but my main concern is that I
run the code and it works for finding "SA", but not "NI" or "DN". Any help
is appreciated.

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Sheets("t0983101").Select
Application.CutCopyMode = False
Range("A4").Select
Dim rngToSearch As Range
Dim wks As Worksheet
Dim rngFound As Range

Set wks = Sheets("t0983101")
Set rngToSearch = wks.Columns(5)

Set rngFound = rngToSearch.Find(what:="SA", LookIn:=xlValues,
lookat:=xlWhole)
If rngFound Is Nothing Then
Sheets("Macro Sheet").Select
End
Else
Do
rngFound.EntireRow.Cut
Sheets("SA").Select
Range("A9").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
Sheets("t0983101").Select

Set rngFound = rngToSearch.FindNext
Loop Until rngFound Is Nothing
End If
Sheets("t0983101").Select
Set wks = Sheets("t0983101")
Set rngToSearch = wks.Columns(5)
Set rngFound = rngToSearch.Find(what:="ni", LookIn:=xlValues)
If rngFound Is Nothing Then
Sheets("Macro Sheet").Select
End
Else
Do
rngFound.EntireRow.Cut
Sheets("ni").Select
Range("A9").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
Sheets("t0983101").Select

Set rngFound = rngToSearch.FindNext
Loop Until rngFound Is Nothing
End If
Set wks = Sheets("t0983101")
Set rngToSearch = wks.Columns(5)
Set rngFound = rngToSearch.Find(what:="DN", LookIn:=xlValues)
If rngFound Is Nothing Then
Sheets("Macro Sheet").Select
End
Else
Do
rngFound.EntireRow.Cut
Sheets("DN").Select
Range("A9").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
Sheets("t0983101").Select

Set rngFound = rngToSearch.FindNext
Loop Until rngFound Is Nothing
End If
end sub


--

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
Loop Function unable to loop Junior728 Excel Programming 1 July 28th 05 10:23 AM
Looping procedure calls userform; how to exit loop (via userform button)? KR Excel Programming 6 July 27th 05 12:57 PM
Problem adding charts using Do-Loop Until loop Chris Bromley[_2_] Excel Programming 2 May 23rd 05 01:31 PM
For/Loop skipping one value in loop only Matt Jensen Excel Programming 6 January 8th 05 12:03 PM
HELP!!!! Can't stop a loop (NOT an infinite loop) TBA[_2_] Excel Programming 3 December 14th 03 03:33 PM


All times are GMT +1. The time now is 02:18 PM.

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"