Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default Macro to find text in all worksheets -pawan

Hi,

Can we arite a mcro to find text/number in all wprksheets of a file at one
time.

Thank You,
Pawan


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default Macro to find text in all worksheets -pawan

Option Explicit
Private results() As String
Private index As Long
Sub BigFind()

Dim startaddress As String
Dim ws As Worksheet
Dim cell As Range
Dim what As String


what = "dog"

For Each ws In Worksheets

Set cell = ws.Cells.Find(what)
If Not cell Is Nothing Then
startaddress = cell.Address
Do
index = index + 1
ReDim Preserve results(1 To 2, 1 To index)
results(1, index) = ws.Name
results(2, index) = cell.Address
Set cell = ws.Cells.FindNext(cell)
Loop While cell.Address < startaddress
End If
Next

Set ws = Worksheets.Add
With ws
.Range(.Range("A1"), .Cells(UBound(results, 2), UBound(results, 1)))
= _
WorksheetFunction.Transpose(results)
End With

End Sub


"Pawan" wrote:

Hi,

Can we arite a mcro to find text/number in all wprksheets of a file at one
time.

Thank You,
Pawan


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default Macro to find text in all worksheets -pawan

Patrick,
Is it possible to name the new worksheet created? The name should be equal
to the text "Search Result_" + the search string. e.g. if I search word
'dog', name of the sheet should be ""Search Result_dog"
Thank You

-Pawan


"Patrick Molloy" wrote:

Option Explicit
Private results() As String
Private index As Long
Sub BigFind()

Dim startaddress As String
Dim ws As Worksheet
Dim cell As Range
Dim what As String


what = "dog"

For Each ws In Worksheets

Set cell = ws.Cells.Find(what)
If Not cell Is Nothing Then
startaddress = cell.Address
Do
index = index + 1
ReDim Preserve results(1 To 2, 1 To index)
results(1, index) = ws.Name
results(2, index) = cell.Address
Set cell = ws.Cells.FindNext(cell)
Loop While cell.Address < startaddress
End If
Next

Set ws = Worksheets.Add
With ws
.Range(.Range("A1"), .Cells(UBound(results, 2), UBound(results, 1)))
= _
WorksheetFunction.Transpose(results)
End With

End Sub


"Pawan" wrote:

Hi,

Can we arite a mcro to find text/number in all wprksheets of a file at one
time.

Thank You,
Pawan


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default Macro to find text in all worksheets -pawan

With ws
.Range(.Range("A1"), .Cells(UBound(results, 2), UBound(results, 1)))
= _
WorksheetFunction.Transpose(results)

.Name = "Results_" & What

End With



just be sure that it name is legitimate - add a test just in case


"Pawan" wrote:

Patrick,
Is it possible to name the new worksheet created? The name should be equal
to the text "Search Result_" + the search string. e.g. if I search word
'dog', name of the sheet should be ""Search Result_dog"
Thank You

-Pawan


"Patrick Molloy" wrote:

Option Explicit
Private results() As String
Private index As Long
Sub BigFind()

Dim startaddress As String
Dim ws As Worksheet
Dim cell As Range
Dim what As String


what = "dog"

For Each ws In Worksheets

Set cell = ws.Cells.Find(what)
If Not cell Is Nothing Then
startaddress = cell.Address
Do
index = index + 1
ReDim Preserve results(1 To 2, 1 To index)
results(1, index) = ws.Name
results(2, index) = cell.Address
Set cell = ws.Cells.FindNext(cell)
Loop While cell.Address < startaddress
End If
Next

Set ws = Worksheets.Add
With ws
.Range(.Range("A1"), .Cells(UBound(results, 2), UBound(results, 1)))
= _
WorksheetFunction.Transpose(results)
End With

End Sub


"Pawan" wrote:

Hi,

Can we arite a mcro to find text/number in all wprksheets of a file at one
time.

Thank You,
Pawan


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
Macro Using 'FIND' function across several worksheets Jennifer Cali Excel Discussion (Misc queries) 2 September 20th 07 08:38 PM
Find text - worksheet function or macro? sebh007 Excel Discussion (Misc queries) 6 January 8th 07 12:53 AM
Hyperlink-Pawan Pawan New Users to Excel 2 August 4th 05 07:14 AM
macro to paste data in alternate cells-pawan Pawan Excel Programming 7 June 21st 05 11:25 PM
how to attach macros to excel permanently - pawan Pawan Excel Programming 4 June 21st 05 10:01 AM


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