FindNext Problem

steve_so

New Member
Joined
Jul 9, 2007
Messages
10
In the worksheet, it may have the "ABC" word in the cells. Now, i need write the marco to find out the "ABC" word. The action are:
1st press the marco button to move the 1st "ABC" word in corrsponding cell
2nd press the marco button to move the 2nd "ABC" word
3rd press the marco button to move the 3rd "ABC" word
.
.
Now, i only can find the 1st "ABC" word even i press the marco button many times from the below VBA command

Code:
Sub FindFail() 
    Dim C As Range 
    Dim SheetNum As Integer 
    SheetNum = 1 
    Do While SheetNum <= Sheets.Count 
         
        Set C = Sheets(SheetNum).Cells.Find("Fail", Range("d41"), SearchOrder:=xlByColumns, LookIn:=xlValues) 
        If Not C Is Nothing Then 
            C.Activate 
            FindAddress =C.Address 
            Do 
                Set C = Sheets(SheetNum.Cells.FindNext(C) 
            Loop While Not C Is Nothing And C.Address <> FindAddress 
        End If 
        SheetNum= SheetNum+ 1 
    Loop 
End Sub

Thanks
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Hi
try
Code:
Sub test()
Dim ws As Worksheet, r As Range, ff As String, n As Long
For Each ws In Sheets
     Set r = ws.Cellls.Find("ABC")
     If Not r Is Nothing Then
          ff = r.Address
          Do
               n = n + 1
               r.Offset(,n).Value = r.Value
               Set r = ws.Cells.FindNext(r)
          Loop Until ff = r.Address
     End If
Next
End Sub
Note: Used Cells.Find according to your code, but how do you find nth found from the result?
 
Upvote 0

Forum statistics

Threads
1,214,821
Messages
6,121,755
Members
449,049
Latest member
excelknuckles

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top