VBA code using .find, .findnext, Do Loop, and InStr function

raivyne

New Member
Joined
Jul 29, 2014
Messages
13
Hello All. I am attempting to write a macro (in Excel 2010) that attempts to find one value from sheeta on sheetb. If the value is found, then I am doing an InStr search to see if a certain string from sheeta is also found in that row of sheetb. If so, then I need to label the H column of sheeta. if not then i want to findnext until all have been found and checked. I am checking muliple rows of sheeta through this loop so that is the reason the For Next is also in the macro.

I am not getting any errors with the macro, but nothing is being labeled - even though i know from previous versions of this macro (using an inefficient looping system that broke down when there was more than 20 rows to look at) that there should be some matches.

Is anyone able to tell me what the issue might be? Thank you in advance.

Code:
Dim anum As Long
Dim match As String
Dim tick As String
Dim found As Range
Dim rcprime As Range

Set R2 = Intersect(sh0.Range("A:A"), sh0.UsedRange)

For rc2 = R2.count To 2 Step -1

'On Error Resume Next

    sh0.Activate

    
    If Cells(rc2, 7).Value = "(100.00)" Then
    
    'On Error Resume Next
        
    anum = sh0.Cells(rc2, 1).Value

    tick = sh0.Cells(rc2, 10).Value
                
    sh1.Activate
                
        Set R1 = Intersect(sh1.Range("A:A"), sh1.UsedRange)
                
        Set found = R1.Find(What:=anum)
        
            If Not found Is Nothing Then
            
                Set rcprime = found
                
                Do
                    
                    sh1.Activate
                    
                    Set found = R1.FindNext(After:=found)
                    
                    If Not found Is Nothing Then
                        
                        If found.Address = rcprime.Address Then Exit Do
                        
                        End If
                        
                        match = Cells(ActiveCell.Row, 5).Value
                        
                        If InStr(match, tick) > 0 Then
                        
                            sh0.Activate
                            
                            ActiveSheet.Cells(rc2, 8) = "RESTRICTED BY TICKER"
                            
                        Else
                        
                            Exit Do
                            
                        End If
                Loop
            
            End If
            
        End If
    
Next
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

Forum statistics

Threads
1,214,911
Messages
6,122,198
Members
449,072
Latest member
DW Draft

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