View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Norman Jones Norman Jones is offline
external usenet poster
 
Posts: 5,302
Default Loop through cells meeting conditions

Hi Huyeote,

Try something like:

'=============
Sub ATester()
Dim x As Range
Dim myRange As Range

Set myRange = Range("B1:B100")

For Each x In myRange
If x.Value 0 _
And x.Offset(0, -1).Value = "A" Then
'do something. e.g.:
MsgBox x.Address
End If
Next x

End Sub
'=============

---
Regards,
Norman



"Huyeote" wrote in
message ...

Hi guys,

Is there any quick way in VBA to code to loop through all cells in a
given range meeting one or more user defined conditions? The
Specialcells method doesn't provide input for user to define a
condition. How to write concise code to do thing like.. (borrow Where
from SQL)

For Each x in myRange Where x 0 And x.Offset(0,-1) ="A"
....

Next x


Thanks,

Huyeote


--
Huyeote
------------------------------------------------------------------------
Huyeote's Profile:
http://www.excelforum.com/member.php...o&userid=13894
View this thread: http://www.excelforum.com/showthread...hreadid=475728