loop to check cells for numbers between 2 number range

O

Olamide

i have a code like this

Columns("A:A").Select ' Find Other Bank and Cash
On Error Resume Next
Selection.Find(What:="89001/43", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Select
If ActiveCell <> 89001/43 Then
Range("A1").Select
Do While Selection < 89000 Or Selection > 89176
Selection.Offset(1, 0).Select
Loop
End If

my problem is that the slash is alway converted to division. Can somebody
pls help me.

thanks
 
O

Olamide

Tom the "Do While Selection < 89000 Or Selection > 89176" will not work if
selection 89001/43
 
D

Don Guillett

What are you trying to do?

Sub findtext1()' finds this text
Columns("a").Find("89001/43").Select
End Sub
 
O

Olamide

what of if i want to find range of 89001/43 to 89001/90 and select cell that
contain the first number within the range. can the quote still work in this.
 
T

Tom Ogilvy

What if 89001/43 isn't there. I thought that was you problem

Sub AABBCC()
Dim l As String, r As String
Dim cell As Range, rng As Range
Dim bfirst As Boolean, bLast As Boolean
Dim cell1 As Range, cell2 As Range
For Each cell In Range("A1", Cells(Rows.Count, 1).End(xlUp))
If Len(cell.Value) > 4 Then
If InStr(cell.Value, "/") Then
l = Left(cell.Value, 5)
r = Right(cell.Value, Len(cell.Value) - _
InStr(1, cell.Value, vbTextCompare) - 1)
If l = "89001" And CLng(r) >= 43 And Not bfirst _
And Not bLast Then
Set cell1 = cell
bfirst = True
End If
' check for /xx > 90
If l = "89001" And CLng(r) > 90 And bfirst Then
Set cell2 = cell.Offset(-1, 0)
bLast = True
Exit For
End If
' check for > 89001/
If l > "89001" And bfirst And Not bLast Then
Set cell2 = cell.Offset(-1, 0)
bLast = True
Exit For
End If
Else
If l > "89001" And bfirst And Not bLast Then
Set cell2 = cell.Offset(-1, 0)
bLast = True
Exit For
End If
End If
End If
Next cell
Range(cell1, cell2).Select
End Sub
Next cell

should select the range of 89001/43 to 89001/90 inclusive assuming the data
is sorted to support this.
 
T

Tom Ogilvy

there is a typo in it anyway.

r = Right(cell.Value, Len(cell.Value) - _
InStr(1, cell.Value, vbTextCompare))

should be

r = Right(cell.Value, Len(cell.Value) - _
InStr(1, cell.Value, "/", vbTextCompare))


but now you should see why I don't spend a lot of time writing code for you
- it would never get used.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top