VBA question about selecting worksheets

J

jlclyde

I am writting some code and i am stuck on how to select a worksheet.
There is a month listed in cell A1 of Sheet1. It is a validated cell
to select months. The rest of the Sheets are labeled named with
months ie. January, February ... Based on what is in cell A1 on
Sheet1, I woudl like the code to select the corresponding sheet. Any
guidance at all woudl be appreciated.

Here is what I ahve so far and it does not work at all.

Sub Tryingsomething()
Dim date1 As String
date1 = Sheet1.Range("A1")
Worksheets(date1).Range("A1").Select
End Sub

Jay
 
K

Kevin B

You could use the following code:

Sub GoWhere()

Dim ws As Worksheet
Dim strMonth As String

Set ws = ThisWorkbook.Sheets(1)

strMonth = ws.Range("A1").Value

Select Case strMonth
Case "January", "February", "March", _
"April", "May", "June", "July", _
"August", "September", "October", _
"November", "December"
ThisWorkbook.Sheets(strMonth).Activate
ActiveSheet.Range("A1").Select
Case Else
End Select

Set ws = Nothing

End Sub
 
G

Gary''s Student

Sub Tryingsomething()
Sheets(Sheets("Sheet1").Range("A1").Value).Activate
Range("A1").Select
End Sub
 
J

jlclyde

Sub Tryingsomething()
Sheets(Sheets("Sheet1").Range("A1").Value).Activate
Range("A1").Select
End Sub

Thanks,
this is eactly what I was looking for. I always seem to forget to
activate the sheet before selecting something on it.
Thanks again,
Jay
 

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

Top