# Looping problems

##### Board Regular
Hi! I have a problem with a loop. I want to search the entire worksheet for a cell that contains the text "Sec type". However there is one cell that contains "Sec type" that I do not want to search, ie if that cell is the only one found containing "Sec type" then the search will have found nothig. Thus, the cell (or the row) that I do not want search is SecID.row. Now the loop searches the spreadsheet but stores in c the forbidden SecID cell. My code:

With Range("b1:aa5000")
Set c = Worksheets("Beräkning").Cells.Find("Sec type", LookIn:=xlValues)
If Not c Is Nothing Then
Do
Set c = .FindNext(c)
Loop While Not c Is Nothing And (c.Address <> firstAddress And (c.row = segment.row Or c.row = secID.row))
End If
End With

I assume that the problem is on the Loop row in the code but I do not know how to write this. Please help! Thank you very much in advance!

### Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Not sure what you want to do...
Code:
``````With Range("b1:aa5000")
Set c = Worksheets("Beräkning").Cells.Find("Sec type", LookIn:=xlValues)
If Not c Is Nothing Then
Do
If c.Row <> segment.Row And c.row <> secId.row Then
' code to do
flg = True
End If
Set c = .FindNext(c)
Else
End If
End With``````

hi! sorry i might have been unclear. when the loop is finished I want to set c= Nothing or something to indicate that the I only found "Sec type" once and that was in the forbidden row (secID.row). Please help me with this! Thanks alot!

Like this?
Code:
``````With Range("b1:aa5000")
Set c = Worksheets("Beräkning").Cells.Find("Sec type", LookIn:=xlValues)
If Not c Is Nothing Then
Do
If c.Row = secId.row Then secId = secId + 1
found = found + 1
Set c = .FindNext(c)
Else
End If
End With
Set c = Nothing
If found = secId Then MsgBox "Only Found " & found & " cells that are all forbidden"``````

Replies
11
Views
451
Replies
8
Views
332
Replies
6
Views
95
Replies
50
Views
2K
Replies
13
Views
758

1,221,384
Messages
6,159,544
Members
451,571
Latest member
Qwissy

### 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.

### Which adblocker are you using?

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

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