Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Noemi
 
Posts: n/a
Default Define a range of cells in VBA

Hi
I have about 20 cells running across which contains data.

What I would like to do is define the range (ie E12:AI12) in VBA so I can do
a check to see if any of those cells in the range contain a specific word.

Thanks
Noemi
  #2   Report Post  
R.VENKATARAMAN
 
Posts: n/a
Default Define a range of cells in VBA

dim myrange as range
set myrange=range("e12:a112")

now you can use <myrange as range
for e.g
myrange.select

==================

"Noemi" wrote in message
...
Hi
I have about 20 cells running across which contains data.

What I would like to do is define the range (ie E12:AI12) in VBA so I can

do
a check to see if any of those cells in the range contain a specific word.

Thanks
Noemi



  #3   Report Post  
Norman Jones
 
Posts: n/a
Default Define a range of cells in VBA

Hi Noemi,

To find each occurrence, try something like:

'=============
Sub Tester()
Dim rng As Range
Dim rCell As Range
Const sStr As String = "fred" '<<==== CHANGE

Set rng = Range("E12:AI12")

For Each rCell In rng.Cells
If Not IsEmpty(rCell.Value) Then
If InStr(1, rCell.Value, sStr, vbTextCompare) Then
'Do something e.g:
MsgBox sStr & " found at " & rCell.Address(0, 0)
Else
'Do something else, or do nothing!
End If
End If
Next

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

---
Regards,
Norman



"Noemi" wrote in message
...
Hi
I have about 20 cells running across which contains data.

What I would like to do is define the range (ie E12:AI12) in VBA so I can
do
a check to see if any of those cells in the range contain a specific word.

Thanks
Noemi



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
Counting Occurrence of Text within Text in Cells in Range. Jeremy N. Excel Worksheet Functions 1 September 8th 05 05:16 AM
Count occurances in range of cells Ed Gregory Excel Worksheet Functions 1 September 7th 05 04:12 PM
Counting empty cells within a range of cells Rosehill - ExcelForums.com New Users to Excel 2 May 2nd 05 08:53 AM
Counting empty cells within a range of cells Rosehill - ExcelForums.com New Users to Excel 0 April 7th 05 12:47 AM
How can I dynamically eliminate blank cells in a given range in E. Scott Steele Excel Worksheet Functions 6 December 17th 04 03:23 AM


All times are GMT +1. The time now is 09:57 PM.

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

About Us

"It's about Microsoft Excel"