Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Grd Grd is offline
external usenet poster
 
Posts: 118
Default Need to find and collect all cells with a certain word onto a shee

Hi there,

I'm new to macros. Could anyone help me with a macro to search for the word
'warranty' on all the sheets and collect all the cells with the word
'warranty' onto a new sheet.

I'm struggling to do this. It sounds very difficult to too.

Any help greatly appreciated

Thanks

Suzanne
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Need to find and collect all cells with a certain word onto a shee

You could try something like this. I don't have time to add the sheet or put
it on the sheet. I'm sure someone else can do that for you.

Sub FindWarranty()

Dim WS As Worksheet
Dim myRange As Range
Dim myNewRange As Range


For Each WS In ActiveWorkbook.Worksheets
Set myNewRange = WS.Cells(1, 1)
Do
Set myRange = myNewRange
Set myNewRange = WS.Cells.Find(What:="Warranty", After:=myRange,
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByColumns,
SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If myRange.Address < myNewRange.Address Then
Debug.Print WS.Name, myNewRange.Address, myNewRange.Value
End If
Loop While myRange.Address < myNewRange.Address
Next WS


End Sub
--
HTH,
Barb Reinhardt



"Grd" wrote:

Hi there,

I'm new to macros. Could anyone help me with a macro to search for the word
'warranty' on all the sheets and collect all the cells with the word
'warranty' onto a new sheet.

I'm struggling to do this. It sounds very difficult to too.

Any help greatly appreciated

Thanks

Suzanne

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Need to find and collect all cells with a certain word onto a shee

This macro records results in a worksheet called "new sheet". It scans thru
all cells in all worksheets looking for the keyword. If a keyword is found
the sheetname, the cell address, and the cell contents are recorded back in
new sheet:

Sub collect_um()
Set nsh = Worksheets("new sheet")
k = 1
For Each sh In Worksheets
If sh.Name < "new sheet" Then
For Each r In sh.UsedRange
If Application.WorksheetFunction.IsText(r) Then
If Len(r.Value) < Len(Replace(r.Value, "warranty", "")) Then
nsh.Cells(k, 1).Value = sh.Name
nsh.Cells(k, 2).Value = r.Address
nsh.Cells(k, 3).Value = r.Value
k = k + 1
End If
End If
Next
End If
Next
End Sub


--
Gary''s Student - gsnu200756


"Grd" wrote:

Hi there,

I'm new to macros. Could anyone help me with a macro to search for the word
'warranty' on all the sheets and collect all the cells with the word
'warranty' onto a new sheet.

I'm struggling to do this. It sounds very difficult to too.

Any help greatly appreciated

Thanks

Suzanne

  #4   Report Post  
Posted to microsoft.public.excel.programming
Grd Grd is offline
external usenet poster
 
Posts: 118
Default Need to find and collect all cells with a certain word onto a

Hi Gary,

Thanks it works

I added the two following lines to create the sheet otherwise I understand
that I need to have a sheet already existing before I ran.

Sheets.Add
ActiveSheet.Name = "new sheet"

Thanks again

"Gary''s Student" wrote:

This macro records results in a worksheet called "new sheet". It scans thru
all cells in all worksheets looking for the keyword. If a keyword is found
the sheetname, the cell address, and the cell contents are recorded back in
new sheet:

Sub collect_um()
Set nsh = Worksheets("new sheet")
k = 1
For Each sh In Worksheets
If sh.Name < "new sheet" Then
For Each r In sh.UsedRange
If Application.WorksheetFunction.IsText(r) Then
If Len(r.Value) < Len(Replace(r.Value, "warranty", "")) Then
nsh.Cells(k, 1).Value = sh.Name
nsh.Cells(k, 2).Value = r.Address
nsh.Cells(k, 3).Value = r.Value
k = k + 1
End If
End If
Next
End If
Next
End Sub


--
Gary''s Student - gsnu200756


"Grd" wrote:

Hi there,

I'm new to macros. Could anyone help me with a macro to search for the word
'warranty' on all the sheets and collect all the cells with the word
'warranty' onto a new sheet.

I'm struggling to do this. It sounds very difficult to too.

Any help greatly appreciated

Thanks

Suzanne

  #5   Report Post  
Posted to microsoft.public.excel.programming
Grd Grd is offline
external usenet poster
 
Posts: 118
Default Need to find and collect all cells with a certain word onto a

Thanks Barb,

I had a play with this and I see it prints what I want to the Immediates
windows.
Thanks to both you and Gary for the help that I needed.

"Barb Reinhardt" wrote:

You could try something like this. I don't have time to add the sheet or put
it on the sheet. I'm sure someone else can do that for you.

Sub FindWarranty()

Dim WS As Worksheet
Dim myRange As Range
Dim myNewRange As Range


For Each WS In ActiveWorkbook.Worksheets
Set myNewRange = WS.Cells(1, 1)
Do
Set myRange = myNewRange
Set myNewRange = WS.Cells.Find(What:="Warranty", After:=myRange,
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByColumns,
SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If myRange.Address < myNewRange.Address Then
Debug.Print WS.Name, myNewRange.Address, myNewRange.Value
End If
Loop While myRange.Address < myNewRange.Address
Next WS


End Sub
--
HTH,
Barb Reinhardt



"Grd" wrote:

Hi there,

I'm new to macros. Could anyone help me with a macro to search for the word
'warranty' on all the sheets and collect all the cells with the word
'warranty' onto a new sheet.

I'm struggling to do this. It sounds very difficult to too.

Any help greatly appreciated

Thanks

Suzanne

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 can I collect specific data from cells in a fill-in form? Sherri at Quality Envelope Excel Discussion (Misc queries) 1 August 13th 08 03:06 PM
Using VLOOKUP to find product from 3 worksheets to put on one shee Bathroom Reno Chick Excel Worksheet Functions 3 May 26th 07 01:01 PM
Use VBA to collect information from Excel cells to av word documen Øyvind Excel Programming 2 October 31st 05 07:21 AM
VBA Problem - How to collect and display text information from applicable cells. LegaLega Excel Programming 0 June 8th 04 07:17 PM
how to read multiple workbooks, collect a few cells from each? ms Excel Programming 1 November 16th 03 01:45 AM


All times are GMT +1. The time now is 05:00 AM.

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"