Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() I made this code as simple as possible to get to the bottom of th problem. Now instead of failing some of the tine, it dies all th time. Any insight please? Sub Macro1() ' For i = 1 To 1000 Columns("A:A").Select FoundIt = Selection.Find(What:=i, _ After:=ActiveCell, _ LookIn:=xlFormulas, _ LookAt:=xlPart, _ SearchOrder:=xlByRows, _ SearchDirection:=xlNext, _ MatchCase:=False, _ SearchFormat:=False).Activate i = i + 1 Next End Su -- GC ----------------------------------------------------------------------- GCF's Profile: http://www.excelforum.com/member.php...nfo&userid=412 View this thread: http://www.excelforum.com/showthread.php?threadid=26694 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() The problem is when the Find function doesn't find anything. If nothin is found, the error is generated. The way around it is to use an erro handler: Sub Macro1() Dim i As Integer Dim FoundIt For i = 1 To 1000 Columns("A:A").Select ON ERROR RESUME NEX FoundIt = Selection.Find(What:=i, _ After:=ActiveCell, _ LookIn:=xlFormulas, _ LookAt:=xlPart, _ SearchOrder:=xlByRows, _ SearchDirection:=xlNext, _ MatchCase:=False, _ SearchFormat:=False).Activate [b]'Here you can check for an error and do what you need to do If Err.Number < 0 Then 'Do something End If i = i + 1 Next End Sub -- kkkni ----------------------------------------------------------------------- kkknie's Profile: http://www.excelforum.com/member.php...nfo&userid=754 View this thread: http://www.excelforum.com/showthread.php?threadid=26694 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
An alternative to using an error handler is - don't try to select nothing.
Sub Macro1() Dim FoundIt as Range For i = 1 To 1000 set FoundIt = Columns("A:A").Find(What:=i, _ After:=Range("A65536"), _ LookIn:=xlFormulas, _ LookAt:=xlPart, _ SearchOrder:=xlByRows, _ SearchDirection:=xlNext, _ MatchCase:=False) if not FoundIt is nothing then ' operate on Foundit ' msgbox Foundit.Address ' ' Foundit.Select Else ' target not found end if i = i + 1 Next End Sub If you want to progressively search down column A, then change After:=Range("A65536") back to After:=ActiveCell and put Range("A65536").Select at the top of the code. -- Regards, Tom Ogilvy "GCF" wrote in message ... I made this code as simple as possible to get to the bottom of the problem. Now instead of failing some of the tine, it dies all the time. Any insight please? Sub Macro1() ' For i = 1 To 1000 Columns("A:A").Select FoundIt = Selection.Find(What:=i, _ After:=ActiveCell, _ LookIn:=xlFormulas, _ LookAt:=xlPart, _ SearchOrder:=xlByRows, _ SearchDirection:=xlNext, _ MatchCase:=False, _ SearchFormat:=False).Activate i = i + 1 Next End Sub -- GCF ------------------------------------------------------------------------ GCF's Profile: http://www.excelforum.com/member.php...fo&userid=4124 View this thread: http://www.excelforum.com/showthread...hreadid=266948 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Visual Basic Error Run Time Error, Type Mismatch | Excel Discussion (Misc queries) | |||
Run time error 1004, General ODBC error | New Users to Excel | |||
Befuddled with For Next Loop ------ Run - Time Error '13' Type Mismatch Error | Excel Programming | |||
Code Error - Run Time Error 5 (Disable Cut, Copy & Paste) | Excel Programming | |||
Run-time error '11' & Run-time error '1004' | Excel Programming |