How can I use a cell value to select a sheet tab?

  • Thread starter Thread starter Monkey-See, Monkey-Do
  • Start date Start date
M

Monkey-See, Monkey-Do

I want to be able to use values in column A (which match the names of the
worksheet tabs in my workbook), to select which sheet I look up (using
VLOOKUP) values in column B from (which contain values contained in one of
those sheets).

I remember I did this once before using INDIRECT or something similar but I
can't remember exactly how - can anyone help?

Cheers
 
Right click sheet tab>view code>copy/paste this.
Now, if you have the name of the sheet tab typed into a cell and double
click on that cell you are taken to the tab.

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
Application.DisplayAlerts = False
Dim WantedSheet As String
WantedSheet = Trim(ActiveCell.Value)
If WantedSheet = "" Then Exit Sub
On Error Resume Next
If Sheets(WantedSheet) Is Nothing Then
' GetWorkbook ' calls another macro to do that
Else
Application.GoTo Sheets(WantedSheet).Range("a1")
End If
Application.DisplayAlerts = True
End Sub
 
Hi,

Is this what you mean

=VLOOKUP(B1,INDIRECT(A1&"!A1:B30"),2,FALSE)

Where a1 contaibs a sheet name.

Mike
 
You VLOOKUP formula will probably have something like this as the
second parameter:

INDIRECT("'"&A1&"'!A:B")

where A1 contains the sheet name and I've assumed you have a two
column table in columns A and B of the sheet where you are trying to
get data from.

Hope this helps.

Pete
 
Thanks Pete,

Spot on!

Cheers from the UK

Pete_UK said:
You VLOOKUP formula will probably have something like this as the
second parameter:

INDIRECT("'"&A1&"'!A:B")

where A1 contains the sheet name and I've assumed you have a two
column table in columns A and B of the sheet where you are trying to
get data from.

Hope this helps.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top