Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 63
Default Set range based on find

Greetings! Through VBA, I'd like to set a range where each
cell in the range contains a value I'm looking for. For
example, assume columns A and B have text values like:

A1: "a,b,c,e"
A2: "d,k,l,m,n"
A3: "b,c,j,t"
B1: "d,e"
etc.

I'd like to loop through each cell in the 2 columns,
looking for "b". If a cell contains "b", then it becomes
part of my new range (call it "rng"). In this case,

Set rng = Range("A1","A3")

Thanks a million!

Jason

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Set range based on find

Sub Findall()
Dim rng As Range, rng1 As Range
Dim rng2 As Range
Set rng = Cells
Set rng1 = rng.Find("b", After:=Range("IV65536"), _
LookIn:=xlValues, Lookat:=xlPart)
If Not rng1 Is Nothing Then
fAddr = rng1.Address
Do
If rng2 Is Nothing Then
Set rng2 = rng1
Else
Set rng2 = Union(rng2, rng1)
End If
Set rng1 = rng.FindNext(rng1)
Loop While rng1.Address < fAddr
End If
If Not rng2 Is Nothing Then
rng2.Select
End If
End Sub


--
Regards,
Tom Ogilvy




"Jason Morin" wrote in message
...
Greetings! Through VBA, I'd like to set a range where each
cell in the range contains a value I'm looking for. For
example, assume columns A and B have text values like:

A1: "a,b,c,e"
A2: "d,k,l,m,n"
A3: "b,c,j,t"
B1: "d,e"
etc.

I'd like to loop through each cell in the 2 columns,
looking for "b". If a cell contains "b", then it becomes
part of my new range (call it "rng"). In this case,

Set rng = Range("A1","A3")

Thanks a million!

Jason



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Set range based on find

If not obvious, then
for just columns A and B, you would change
Set rng = Cells
to
Set rng = Range("A:B")

--
Regards,
Tom Ogilvy

"Jason Morin" wrote in message
...
Greetings! Through VBA, I'd like to set a range where each
cell in the range contains a value I'm looking for. For
example, assume columns A and B have text values like:

A1: "a,b,c,e"
A2: "d,k,l,m,n"
A3: "b,c,j,t"
B1: "d,e"
etc.

I'd like to loop through each cell in the 2 columns,
looking for "b". If a cell contains "b", then it becomes
part of my new range (call it "rng"). In this case,

Set rng = Range("A1","A3")

Thanks a million!

Jason



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
Find range a value fits to, assign new value based on importance RiverCity Excel Worksheet Functions 0 November 9th 08 05:01 AM
Find category value based on date range? thewiz1972 Excel Worksheet Functions 5 June 10th 06 03:28 AM
find minimum of range based on multiple criteria Weissme Excel Worksheet Functions 3 May 21st 06 05:21 PM
Need to find Min value based on date range entered Chad S Excel Worksheet Functions 0 October 28th 04 08:03 PM
Need to find Min value based on date range entered Chad S Excel Worksheet Functions 1 October 28th 04 09:52 AM


All times are GMT +1. The time now is 03:42 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"