Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
Joe Joe is offline
external usenet poster
 
Posts: 476
Default Listing of cell references from a FIND All command.

Can the results (cell references) obtained after using "EDIT/FIND/Find All"
command be placed into a column array?

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default Listing of cell references from a FIND All command.

Let's say we are looking for "happiness" where ever it occurs on a single
sheet. Try this code:

Sub joe()
Dim listit As Range
Set listit = Nothing
x = "happiness"
For Each r In ActiveSheet.UsedRange
If InStr(1, r.Value, x, 1) < 0 Then
If listit Is Nothing Then
Set listit = r
Else
Set listit = Union(listit, r)
End If
End If
Next

If listit Is Nothing Then
Else
i = 1
For Each r In listit
Cells(i, "A").Value = r.Address
i = i + 1
Next
End If
End Sub

1. it uses column A for the results
2. it only looks on a single sheet
3. it can be modified for numerical values
4. there is a danger that the results can over-write data
--
Gary''s Student - gsnu200718


"Joe" wrote:

Can the results (cell references) obtained after using "EDIT/FIND/Find All"
command be placed into a column array?

  #3   Report Post  
Posted to microsoft.public.excel.misc
Joe Joe is offline
external usenet poster
 
Posts: 476
Default Listing of cell references from a FIND All command.

It works very well. Would it be possible to inlcude the total cells found and
place it at say A1 or somewhere else on the sheet. It would be nice to get a
message if zero occurrences were found. Also can "happiness" be read by the
VBA macro from a paticular cell.
Many thanks

"Gary''s Student" wrote:

Let's say we are looking for "happiness" where ever it occurs on a single
sheet. Try this code:

Sub joe()
Dim listit As Range
Set listit = Nothing
x = "happiness"
For Each r In ActiveSheet.UsedRange
If InStr(1, r.Value, x, 1) < 0 Then
If listit Is Nothing Then
Set listit = r
Else
Set listit = Union(listit, r)
End If
End If
Next

If listit Is Nothing Then
Else
i = 1
For Each r In listit
Cells(i, "A").Value = r.Address
i = i + 1
Next
End If
End Sub

1. it uses column A for the results
2. it only looks on a single sheet
3. it can be modified for numerical values
4. there is a danger that the results can over-write data
--
Gary''s Student - gsnu200718


"Joe" wrote:

Can the results (cell references) obtained after using "EDIT/FIND/Find All"
command be placed into a column array?

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default Listing of cell references from a FIND All command.

Hi Joe:

Sub joe2()
Dim listit As Range
Set listit = Nothing
x = Range("A1").Value
For Each r In ActiveSheet.UsedRange
If InStr(1, r.Value, x, 1) < 0 Then
If listit Is Nothing Then
Set listit = r
Else
Set listit = Union(listit, r)
End If
End If
Next
Range("A2").Value = listit.Count - 1
If listit.Count = 1 Then
MsgBox ("nothing found")
Else
i = 3
For Each r In listit
Cells(i, "A").Value = r.Address
i = i + 1
Next
End If
End Sub


Different version, different name.

1. put the searched-for value in A1
2. leave A2 empty

The macro will now put the count in A2 and start the list in A3.
--
Gary''s Student - gsnu200718


"Joe" wrote:

It works very well. Would it be possible to inlcude the total cells found and
place it at say A1 or somewhere else on the sheet. It would be nice to get a
message if zero occurrences were found. Also can "happiness" be read by the
VBA macro from a paticular cell.
Many thanks

"Gary''s Student" wrote:

Let's say we are looking for "happiness" where ever it occurs on a single
sheet. Try this code:

Sub joe()
Dim listit As Range
Set listit = Nothing
x = "happiness"
For Each r In ActiveSheet.UsedRange
If InStr(1, r.Value, x, 1) < 0 Then
If listit Is Nothing Then
Set listit = r
Else
Set listit = Union(listit, r)
End If
End If
Next

If listit Is Nothing Then
Else
i = 1
For Each r In listit
Cells(i, "A").Value = r.Address
i = i + 1
Next
End If
End Sub

1. it uses column A for the results
2. it only looks on a single sheet
3. it can be modified for numerical values
4. there is a danger that the results can over-write data
--
Gary''s Student - gsnu200718


"Joe" wrote:

Can the results (cell references) obtained after using "EDIT/FIND/Find All"
command be placed into a column array?

  #5   Report Post  
Posted to microsoft.public.excel.misc
Joe Joe is offline
external usenet poster
 
Posts: 476
Default Listing of cell references from a FIND All command.

This works brilliantly, however it does count the word in A1 giving a count
of one too many. I have another question. When searching for the word "in"
your macro will find it in "happiness". Can I write x=" in " in the first
macro? Or put a space before the text "in" into cell A1?

"Gary''s Student" wrote:

Hi Joe:

Sub joe2()
Dim listit As Range
Set listit = Nothing
x = Range("A1").Value
For Each r In ActiveSheet.UsedRange
If InStr(1, r.Value, x, 1) < 0 Then
If listit Is Nothing Then
Set listit = r
Else
Set listit = Union(listit, r)
End If
End If
Next
Range("A2").Value = listit.Count - 1
If listit.Count = 1 Then
MsgBox ("nothing found")
Else
i = 3
For Each r In listit
Cells(i, "A").Value = r.Address
i = i + 1
Next
End If
End Sub


Different version, different name.

1. put the searched-for value in A1
2. leave A2 empty

The macro will now put the count in A2 and start the list in A3.
--
Gary''s Student - gsnu200718


"Joe" wrote:

It works very well. Would it be possible to inlcude the total cells found and
place it at say A1 or somewhere else on the sheet. It would be nice to get a
message if zero occurrences were found. Also can "happiness" be read by the
VBA macro from a paticular cell.
Many thanks

"Gary''s Student" wrote:

Let's say we are looking for "happiness" where ever it occurs on a single
sheet. Try this code:

Sub joe()
Dim listit As Range
Set listit = Nothing
x = "happiness"
For Each r In ActiveSheet.UsedRange
If InStr(1, r.Value, x, 1) < 0 Then
If listit Is Nothing Then
Set listit = r
Else
Set listit = Union(listit, r)
End If
End If
Next

If listit Is Nothing Then
Else
i = 1
For Each r In listit
Cells(i, "A").Value = r.Address
i = i + 1
Next
End If
End Sub

1. it uses column A for the results
2. it only looks on a single sheet
3. it can be modified for numerical values
4. there is a danger that the results can over-write data
--
Gary''s Student - gsnu200718


"Joe" wrote:

Can the results (cell references) obtained after using "EDIT/FIND/Find All"
command be placed into a column array?



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default Listing of cell references from a FIND All command.

Yes you can. If you are searching for " in ", then put it in A1. This will
exclude finding "happiness". By the way, if you want to find cells with a
specific value only, then try joe3:


Sub joe3()
Dim listit As Range
Set listit = Nothing
x = Range("A1").Value
For Each r In ActiveSheet.UsedRange
If r.Value = x Then
If listit Is Nothing Then
Set listit = r
Else
Set listit = Union(listit, r)
End If
End If
Next
Range("A2").Value = listit.Count - 1
If listit.Count = 1 Then
MsgBox ("nothing found")
Else
i = 3
For Each r In listit
Cells(i, "A").Value = r.Address
i = i + 1
Next
End If
End Sub

Only one line of joe2 was changed to make joe3. This version will find
"joy", but will ignore "joy to the world"
--
Gary''s Student - gsnu200718

  #7   Report Post  
Posted to microsoft.public.excel.misc
Joe Joe is offline
external usenet poster
 
Posts: 476
Default Listing of cell references from a FIND All command.

Thanks for that code. What would be a good reference book for an
introduction to VBA for excel since it seems to be so useful and powerful?

"Gary''s Student" wrote:

Yes you can. If you are searching for " in ", then put it in A1. This will
exclude finding "happiness". By the way, if you want to find cells with a
specific value only, then try joe3:


Sub joe3()
Dim listit As Range
Set listit = Nothing
x = Range("A1").Value
For Each r In ActiveSheet.UsedRange
If r.Value = x Then
If listit Is Nothing Then
Set listit = r
Else
Set listit = Union(listit, r)
End If
End If
Next
Range("A2").Value = listit.Count - 1
If listit.Count = 1 Then
MsgBox ("nothing found")
Else
i = 3
For Each r In listit
Cells(i, "A").Value = r.Address
i = i + 1
Next
End If
End Sub

Only one line of joe2 was changed to make joe3. This version will find
"joy", but will ignore "joy to the world"
--
Gary''s Student - gsnu200718

  #8   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default Listing of cell references from a FIND All command.

Hi Joe:

There are many good books & resources:

1. start with:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

2. practice using the Recorder

3. acquire something like:
Walkenbach's Power Programming with VBA
--
Gary''s Student - gsnu200718

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
How to find duplicate data in two tables,then listing it? Doeu Excel Worksheet Functions 2 April 20th 06 12:33 PM
How to find duplicate data in two tables,then listing it?(Excel) Doeu Excel Worksheet Functions 0 April 20th 06 09:57 AM
Using Find & Replace to edit cell references in links Matt7102 Excel Discussion (Misc queries) 0 March 15th 06 08:50 PM
find all references to a particular cell singlgl1 Excel Discussion (Misc queries) 2 August 21st 05 02:56 AM
Excel has a "Find Next" command but no "Find Previous" command. Michael Fitzpatrick Excel Discussion (Misc queries) 2 January 10th 05 11:45 PM


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