Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
ann ann is offline
external usenet poster
 
Posts: 210
Default Looping through cells using VBA

I need to look through a range of cells to see if there is a match to a
variable I have previously set. What is the syntax for referencing this
range? Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Looping through cells using VBA

Dim rng as Range, rng1 as Range
Dim myVar as String

myVar = "Amy"
set rng = Range("B9:F100")

set rng1 = rng.find(myVar)
if not rng1 is nothing then
msgbox myvar & " found at " & rng1.Address
Else
msgbox myvar & " was not found in " & rng.Address
End sub

--
Regards,
Tom Ogilvy

"Ann" wrote in message
...
I need to look through a range of cells to see if there is a match to a
variable I have previously set. What is the syntax for referencing this
range? Thanks.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Looping through cells using VBA

For Each c In Range("A1:A10")
If c.Text = "WHATEVER YOUR LOOKING FOR" Then
..... Do what you want here
End If
Next c

In the example change the range to whatever you want and the check
condition.

This way you have multiple check conditions within a case statement and as
each cell is returned you can manipulate each cell very easily.

"Ann" wrote in message
...
I need to look through a range of cells to see if there is a match to a
variable I have previously set. What is the syntax for referencing this
range? Thanks.



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
reference cells when looping Isis[_2_] Excel Discussion (Misc queries) 5 April 29th 10 11:43 PM
Looping thru a range of cells COBOL Dinosaur New Users to Excel 9 June 2nd 07 03:41 AM
Looping on Cells with $x$y D.Parker Excel Programming 4 March 25th 05 11:31 AM
Looping through Cells Gary Paris[_2_] Excel Programming 5 December 25th 04 08:46 PM
Looping through a range of cells rEN Excel Programming 4 June 10th 04 06:28 PM


All times are GMT +1. The time now is 10:19 AM.

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"