Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default Need help with my looping macro

I can't seam to figure out how to get this to loop until
the words "No Match" are not found in the limited search
for range. I can get to loop a couple of times but once
it does not find a match any further it crashes. Run time
13 type mismatch is the most common.


Sub Add_New_CAD_Customer()

Dim wks As Worksheet
Dim rngToSearch As Range
Dim rngFound As Range
Dim rngFirst As Range
Dim celltofind As Range
Set celltofind = Cells.Find(What:="No Match",
After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)

Set wks = ActiveSheet
Set rngToSearch = wks.Range("AF3:AF20")
Set rngFound = rngToSearch.Find("No Match", , xlValues,
xlPart)

If Not rngFound Is Nothing Then
Set rngFirst = rngFound

Do
Range("A3:T3").Select
Selection.Insert Shift:=xlDown
Range("A4:T4").Select
Selection.Copy
Range("A3").Select
Selection.PasteSpecial
Paste:=xlPasteFormats

Set rngFound = rngToSearch.FindNext(rngFound)
Set rngToSearch = wks.Range("AF3:AF20")
Set rngFound = rngToSearch.Find("No Match", ,
xlValues, xlPart)
rngToSearch.Find("No Match").Select

ActiveCell.ClearContents
ActiveCell.Offset(0, -6).Range
("A1:B1").Select
Selection.Copy
Range("B3").Select
Selection.PasteSpecial
Paste:=xlPasteValues
Loop Until celltofind is empty
End If
End Sub

Any suggestions
Pete W
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default Need help with my looping macro

What are you trying to do? I get the part where you are trying to find the
words "no Match". Based on finding that you want to do what exactly?

"Pete" wrote:

I can't seam to figure out how to get this to loop until
the words "No Match" are not found in the limited search
for range. I can get to loop a couple of times but once
it does not find a match any further it crashes. Run time
13 type mismatch is the most common.


Sub Add_New_CAD_Customer()

Dim wks As Worksheet
Dim rngToSearch As Range
Dim rngFound As Range
Dim rngFirst As Range
Dim celltofind As Range
Set celltofind = Cells.Find(What:="No Match",
After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)

Set wks = ActiveSheet
Set rngToSearch = wks.Range("AF3:AF20")
Set rngFound = rngToSearch.Find("No Match", , xlValues,
xlPart)

If Not rngFound Is Nothing Then
Set rngFirst = rngFound

Do
Range("A3:T3").Select
Selection.Insert Shift:=xlDown
Range("A4:T4").Select
Selection.Copy
Range("A3").Select
Selection.PasteSpecial
Paste:=xlPasteFormats

Set rngFound = rngToSearch.FindNext(rngFound)
Set rngToSearch = wks.Range("AF3:AF20")
Set rngFound = rngToSearch.Find("No Match", ,
xlValues, xlPart)
rngToSearch.Find("No Match").Select

ActiveCell.ClearContents
ActiveCell.Offset(0, -6).Range
("A1:B1").Select
Selection.Copy
Range("B3").Select
Selection.PasteSpecial
Paste:=xlPasteValues
Loop Until celltofind is empty
End If
End Sub

Any suggestions
Pete W

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
Macro looping? klh84 Excel Worksheet Functions 3 February 26th 10 05:58 PM
Looping Macro KimC Excel Discussion (Misc queries) 1 January 11th 10 04:55 AM
Looping Macro Jase Excel Discussion (Misc queries) 5 March 12th 08 09:08 PM
Looping macro RK Excel Worksheet Functions 2 December 12th 06 11:29 PM
Looping a macro Sony Excel Discussion (Misc queries) 3 October 30th 06 11:52 AM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"