Need help searching entire workbook and not just a single sheet

scubadivingfool

New Member
Joined
Jun 17, 2010
Messages
35
Hello All

I need help modifying the code below to look through the entire workbook searching for "$" instead of just one. I would love it if it could just search for CGYSR-"##". I have had help putting the code together as I am new to VBA

Here is the code:

Option Explicit

Sub FindPriceTagInformation()
Dim FirstAddress As String
Dim MyArr As Variant
Dim Rng As Range
Dim Rcount As Long
Dim I As Long
Dim NewSh As Worksheet


With Application
.ScreenUpdating = False
.EnableEvents = False
End With

'Fill in the search Value
MyArr = Array("$")

Set NewSh = Sheets("Sheet2")

With Sheets("CGYSR-3").Range("A1:ZZ300")

Rcount = 0

For I = LBound(MyArr) To UBound(MyArr)


Set Rng = .Find(What:=MyArr(I), _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)

If Not Rng Is Nothing Then
FirstAddress = Rng.Address
Do
Rcount = Rcount + 1
NewSh.Cells(Rcount, 3).Value = Rng.Value

NewSh.Cells(Rcount, 2).Value = Rng.Offset(-3, 0).Value
NewSh.Cells(Rcount, 1).Value = Rng.Offset(-5, 0).Value

Set Rng = .FindNext(Rng)
Loop While Not Rng Is Nothing And Rng.Address <> FirstAddress
End If
Next I
End With

With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Can you try something like this?

VBA Code:
Option Explicit

Sub FindPriceTagInformation()
Dim FirstAddress As String
Dim MyArr As Variant
Dim Rng As Range
Dim Rcount As Long
Dim I As Long
Dim NewSh As Worksheet

Dim ws As Worksheet

With Application
.ScreenUpdating = False
.EnableEvents = False
End With

'Fill in the search Value
MyArr = Array("$")

Set NewSh = Sheets("Sheet2")



For Each ws In ThisWorkbook.Worksheets

    If Left(ws.Name, 7) = "CGYSR-3" Then

        With ws.Range("A1:ZZ300")
            
            Rcount = 0
            
            For I = LBound(MyArr) To UBound(MyArr)
            
                
                Set Rng = .Find(What:=MyArr(I), _
                After:=.Cells(.Cells.Count), _
                LookIn:=xlValues, _
                LookAt:=xlPart, _
                SearchOrder:=xlByRows, _
                SearchDirection:=xlNext, _
                MatchCase:=False)
                
                If Not Rng Is Nothing Then
                FirstAddress = Rng.Address
                Do
                Rcount = Rcount + 1
                NewSh.Cells(Rcount, 3).Value = Rng.Value
                
                NewSh.Cells(Rcount, 2).Value = Rng.Offset(-3, 0).Value
                NewSh.Cells(Rcount, 1).Value = Rng.Offset(-5, 0).Value
                
                Set Rng = .FindNext(Rng)
                Loop While Not Rng Is Nothing And Rng.Address <> FirstAddress
                End If
            Next I
            
        End With
        
    End If
Next ws

With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top