Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default find a word in sheet

Dear all,

I want to use VBA to look for a word (for example "AAA") in one sheet.
but I want to find this word sheet by sheet and then copy the this word (if
find) to another sheet (for example,copy this word to sheet1)

I don't know how to loop the sheet(one by one) and how to look for this
work and then copy this word to another sheet.

Thank you
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default find a word in sheet

Sub FindThings()
Dim s As String, i As Long
s = "AAA"
i = 1

Dim w As Worksheet, results As Worksheet
Set ws = Sheets(Array("Sheet1", "Sheet2", "Sheet3"))
Set results = Sheets("results")

Dim r As Range, rr As Range

For Each w In ws
w.Activate
Set r = ActiveSheet.UsedRange
For Each rr In r
If rr.Value = s Then
results.Cells(i, 1) = w.Name
results.Cells(i, 2) = rr.Address
results.Cells(i, 3) = s
i = i + 1
End If
Next
Next
End Sub

Here we create an array of three worksheets. We loop over this array and in
each worksheet search for AAA. When we find AAA, we record the source in a
worksheet called results. We record the name of the sheet, the address
within the sheet and the value.

This can easily be modified to look for AAA within other text.
--
Gary''s Student - gsnu200909


"John" wrote:

Dear all,

I want to use VBA to look for a word (for example "AAA") in one sheet.
but I want to find this word sheet by sheet and then copy the this word (if
find) to another sheet (for example,copy this word to sheet1)

I don't know how to loop the sheet(one by one) and how to look for this
work and then copy this word to another sheet.

Thank you

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default find a word in sheet

Anotherway using Find & FindNext which should be quicker..

Sub Macro()

Dim varFound As Variant, varSearch As Variant, ws As Worksheet
Dim strAddress As String, intCount As Integer, intSheet As Integer

varSearch = "word"

For intSheet = 2 To Sheets.Count
Set ws = Worksheets(intSheet)
Set varFound = ws.Cells.Find(varSearch, , xlValues, xlPart)
If Not varFound Is Nothing Then
strAddress = varFound.Address
Do
intCount = intCount + 1
Sheets("Sheet1").Range("A" & intCount) = ws.Name
Sheets("Sheet1").Range("B" & intCount) = strAddress
Sheets("Sheet1").Range("C" & intCount) = varFound.Text
Set varFound = ws.Cells.FindNext(varFound)
Loop While Not varFound Is Nothing And _
varFound.Address < strAddress
End If
Next

End Sub

If this post helps click Yes
---------------
Jacob Skaria


"John" wrote:

Dear all,

I want to use VBA to look for a word (for example "AAA") in one sheet.
but I want to find this word sheet by sheet and then copy the this word (if
find) to another sheet (for example,copy this word to sheet1)

I don't know how to loop the sheet(one by one) and how to look for this
work and then copy this word to another sheet.

Thank you

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 a particular word? Jack Excel Worksheet Functions 20 December 2nd 09 12:04 PM
Macro to find a word and copy all rows with this word to diff ws Chas Excel Programming 3 April 27th 07 11:16 PM
macro to intsert a word using the "Find" command to search for a word Stuart[_3_] Excel Programming 1 November 29th 06 05:13 AM
find word Ron Excel Programming 2 August 23rd 06 05:29 PM
Find Whole Word Only Lonely[_3_] Excel Programming 2 December 11th 03 04:41 PM


All times are GMT +1. The time now is 08:49 PM.

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"