Look up

  • Thread starter Thread starter Greg B
  • Start date Start date
G

Greg B

I want to have a macro that will look for the corresponding sheet to the
reference in cell "a2"

Is this possible and how is it possible

Thanks

Greg
 
try something like this code(the name of the sheet is in A2 of sheet1)

Worksheets(Worksheets("sheet1").Range("a2").Value).Activate
 
Hi Greg,

Try this macro:

Dim ws as Worksheet

For Each ws in ThisWorkbook.Sheets
If (ws.Name = ThisWorkbook.ActiveSheet.Range ("A2") then
' do something here if the worksheet exists
Exit for
end if
Next ws
 
Nice solutions, but it will break if the sheet name in A2 doesn't exist
 
You could add bit of error checking:

On error resume next
Worksheets(Worksheets("sheet1").Range("a2").Value).Activate
if err.number <> 0 then
msgbox "That sheet doesn't exist
err.clear
end if
 
Thank you to everyone who have helped me

Greg
Dave Peterson said:
You could add bit of error checking:

On error resume next
Worksheets(Worksheets("sheet1").Range("a2").Value).Activate
if err.number <> 0 then
msgbox "That sheet doesn't exist
err.clear
end if
 

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

Similar Threads

Look up & auto populate between sheets 7
Excel Conditional Formatting 1
Help to create a macro 2
Excel Monthly Spread sheet. 12
Copying conditional formating 2
Indirect or Index or something else 1
Macro-Copy/add 3
Timestamp 3

Back
Top