Macro - Find String based on data in a cell

SammiBoi

Board Regular
Joined
Jun 1, 2007
Messages
77
I tried making a macro would would basically condense the drilldown of a Pivot Table by only copying out certain columns that I would want.

Code:
Currentfile = ActiveWorkbook.Name
Extractor = "ARO Pivot Table Extractor 1.0.xls"

Windows(Currentfile).Activate
Range("A1").Select
    
Dim Found As Range
Set Found = Cells.find(What:="Outlet #", After:=ActiveCell, LookIn:=xlValues, _
        LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False)
If Not Found Is Nothing Then Range(Found, Found.End(xlDown).Offset(2000, 0)).Select
Selection.Copy

Windows(Extractor).Activate
    Sheets("Data").Select
    Range("A1").Select
    ActiveSheet.Paste

this has work quite well, but I was wondering if I can make this a little more dynamic so that I can easily apply this to future Pivot Tables. That is, if I were to put my search term on ARO Pivot Table Extractor 1.0.xls's Sheet1's Cell A1, can I then get the macro to just do a search of the string in that cell on my other worksheet? (in this case it would do a search of cell A1 on the other active workbook and return th response in Extractor's Data Sheet in Column A)

Thanks in advance
Sam
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.

SammiBoi

Board Regular
Joined
Jun 1, 2007
Messages
77
I made a little more change in the Find part of the macro, but it still doesn't seem to be working....

Code:
Set Found = Cells.find(What:=Workbooks("ARO Pivot Table Extractor 1.0.xls").Worksheets("Sheet1").Cells("A1"), After:=ActiveCell, LookIn:=xlValues, _
        LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,191,166
Messages
5,985,050
Members
439,935
Latest member
Monty238

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
Top