Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Loop through cells meeting conditions


Hi guys,

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

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

Next x


Thanks,

Huyeot

--
Huyeot
-----------------------------------------------------------------------
Huyeote's Profile: http://www.excelforum.com/member.php...fo&userid=1389
View this thread: http://www.excelforum.com/showthread.php?threadid=47572

  #2   Report Post  
Posted to microsoft.public.excel.programming
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Loop through cells meeting conditions


This is a snippet of my code that allowed me to go through each cell in
a column to check for certain criteria, that a certain checkbox was
chosen and a certain value in a given range of a column was chosen.

Dim Ct As Integer
Ct = 0

If ckHome2 = True Then
Range("d2").Select
Do
If IsEmpty(ActiveCell) = False Then
ActiveCell.Offset(1, 0).Select
End If
If ActiveCell.Value = "Home" Then
Ct = Ct + 1
txtHome2.Text = Ct
End If

Hope this helps some.
Barb


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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Meeting 12 formatted conditions Loadmaster Excel Discussion (Misc queries) 9 July 25th 08 03:16 AM
sum a range meeting conditions of row & column jwang036 Excel Worksheet Functions 2 April 21st 08 06:28 AM
using sumproduct on subtotals meeting certain conditions Jeff Manning Excel Worksheet Functions 0 November 10th 05 12:35 AM
Meeting two conditions before summing Andeb Excel Worksheet Functions 1 June 24th 05 10:33 AM
Loop through data for conditions and create a new sheet Mackay 1979 Excel Programming 3 September 6th 04 11:58 PM


All times are GMT +1. The time now is 07:02 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"