VBA Activate a sheet from another Workbook based on Cell Value

decadence

Well-known Member
Joined
Oct 9, 2015
Messages
525
Office Version
  1. 365
  2. 2016
  3. 2013
  4. 2010
  5. 2007
Platform
  1. Windows
Hi I have a lookup workbook with 50+ sheets of data and I would like to activate a specific work sheet from that workbook if a cell in the active sheet containing a specific value matches the sheet name, Is this possible to do this?
 
Basically There will be multiple different workbooks of data that will contain one of these words in the array but not sure which one as there is varying rows of data in every workbook with up to 10,000 rows of data per workbook, hence trying to match the word against the lookup workbook would make it a lot easier and faster to do
 
Upvote 0

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
The way this macro is written, it would have to be copied into a regular module in every different workbook of data that will contain one of the search words and each workbook would have to be saved as a macro-enabled file. The macro would then be run from each workbook. Change the names in the array to match the words that you want to search for.
Code:
Sub SelectSheet()
    Application.ScreenUpdating = False
    Dim foundVal As Range
    Dim myArray As Variant
    myArray = Array("Word1", "Word2", "Word3", "Word4")
    Dim i As Long
    For i = LBound(myArray) To UBound(myArray)
        Set foundVal = ActiveSheet.UsedRange.Find(myArray(i), LookIn:=xlValues, lookat:=xlWhole)
        If Not foundVal Is Nothing Then
            Workbooks("Data Lookup 2018.xlsx").Activate
            Workbooks("Data Lookup 2018.xlsx").Sheets(foundVal.Value).Select
            Exit For
        End If
    Next i
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Thank you mumps this is exactly what I need, much appreciated as I have been struggling to get my head round this one for a while.
 
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