Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 178
Default Sheet Select Macro

I have the folowing macro that works on one of my excel workbooks.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim ws As Worksheet
If Not Intersect(Target, Range("B3:B52")) Is Nothing Then
On Error Resume Next
Set ws = Worksheets(Target.Row)
If ws Is Nothing Then
MsgBox "Sorry, but there is no worksheet named " & Target.Row
Else
ws.Activate
End If
End If
End Sub

This selects the sheet that corresponds to the cell. but I have cells in
J3:J52 as well but cant select the sheets that correspond to those can anyone
help?

Regards

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Sheet Select Macro

Hi,

I don't understand. because you are using target.row if you select B3 it
will look for a sheet called 3 so if you extend this range as below then
selecting J3 will do exactly the same as selecting B3. If you have sheet
names in these cells perhaps you should be using

Set ws = Worksheets(Target.Text)

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim ws As Worksheet
If Not Intersect(Target, Range("B3:B52, J3:J52")) Is Nothing Then
On Error Resume Next
Set ws = Worksheets(Target.Row)
If ws Is Nothing Then
MsgBox "Sorry, but there is no worksheet named " & Target.Row
Else
ws.Activate
End If
End If
End Sub

Mike

"santaviga" wrote:

I have the folowing macro that works on one of my excel workbooks.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim ws As Worksheet
If Not Intersect(Target, Range("B3:B52")) Is Nothing Then
On Error Resume Next
Set ws = Worksheets(Target.Row)
If ws Is Nothing Then
MsgBox "Sorry, but there is no worksheet named " & Target.Row
Else
ws.Activate
End If
End If
End Sub

This selects the sheet that corresponds to the cell. but I have cells in
J3:J52 as well but cant select the sheets that correspond to those can anyone
help?

Regards

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 178
Default Sheet Select Macro


This is what I have and need to do.

Cells B3:B52 (once clicked on one of these cells select the corresponding
sheet number)
Cells J3:J52 the same sheet numbers 50 to 100
Cells R3:R52 sheet numbers 100 to 150

So when I click on R3 this will open sheet number 100 and so on for all the
cells in B, J and R

Thanks

"Mike H" wrote:

Hi,

I don't understand. because you are using target.row if you select B3 it
will look for a sheet called 3 so if you extend this range as below then
selecting J3 will do exactly the same as selecting B3. If you have sheet
names in these cells perhaps you should be using

Set ws = Worksheets(Target.Text)

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim ws As Worksheet
If Not Intersect(Target, Range("B3:B52, J3:J52")) Is Nothing Then
On Error Resume Next
Set ws = Worksheets(Target.Row)
If ws Is Nothing Then
MsgBox "Sorry, but there is no worksheet named " & Target.Row
Else
ws.Activate
End If
End If
End Sub

Mike

"santaviga" wrote:

I have the folowing macro that works on one of my excel workbooks.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim ws As Worksheet
If Not Intersect(Target, Range("B3:B52")) Is Nothing Then
On Error Resume Next
Set ws = Worksheets(Target.Row)
If ws Is Nothing Then
MsgBox "Sorry, but there is no worksheet named " & Target.Row
Else
ws.Activate
End If
End If
End Sub

This selects the sheet that corresponds to the cell. but I have cells in
J3:J52 as well but cant select the sheets that correspond to those can anyone
help?

Regards

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to go to select sheet Kevin Excel Discussion (Misc queries) 2 December 18th 07 02:28 AM
Select a sheet by name in a macro swatsp0p[_49_] Excel Programming 5 June 8th 06 08:24 PM
macro sheet select Dave K Excel Discussion (Misc queries) 2 October 21st 05 10:08 PM
Macro, select Sheet "Number", NOT Sheet Name DAA Excel Worksheet Functions 4 November 30th 04 05:29 PM
Help! Macro to select all sheet from AA to ZZ Don Guillett[_4_] Excel Programming 4 May 28th 04 02:47 AM


All times are GMT +1. The time now is 11:53 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"