Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Using Target.Row in other Sheets

I am trying to select cells in several sheets, if the user is in Sheet1 and
selects a cell in column A. I get a '1004' error ("Select method of Range
class failed") at Range("A" & Target.Row).Select. Can somebody help me?
Here is my code:

.... If Target.Cells.Count = 1 Then
1: ' if they select a cell in Col 1, select complementary cell in other
sheets
If Target.Column = 1 And Target.Value < "" Then
Sheets(3).Select
Range("A" & Target.Row).Select
Sheets(4).Range("A" & Target.Row).Sheets(5).Select
Sheets(1).Select
EndIf
EndIf
....

TIA


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default Using Target.Row in other Sheets

Why? There is probably an easier way to do what you want if we knew what it
is that you want.

"zSplash" <zNOSPAMSplash@ gci.net wrote in message
...
I am trying to select cells in several sheets, if the user is in Sheet1

and
selects a cell in column A. I get a '1004' error ("Select method of Range
class failed") at Range("A" & Target.Row).Select. Can somebody help me?
Here is my code:

... If Target.Cells.Count = 1 Then
1: ' if they select a cell in Col 1, select complementary cell in

other
sheets
If Target.Column = 1 And Target.Value < "" Then
Sheets(3).Select
Range("A" & Target.Row).Select
Sheets(4).Range("A" & Target.Row).Sheets(5).Select
Sheets(1).Select
EndIf
EndIf
...

TIA




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Using Target.Row in other Sheets


You can only select on the activesheet.

On Error goto ErrHandler
Dim sh as Worksheet
Dim sAddr as String
if Target.Count 1 then exit sub
If Target.Column = 1 And Target.Value < "" Then
sAddr = target.Address
Application.ScreenUpdating = False
Application.EnableEvents = False
for each sh in worksheets(Array("sheet2","Sheet3","Sheet4","Sheet 5"))
sh.Activate
sh.Range(sAddr).Select
Next
me.activate

End if
ErrHandler
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub

--
Regards,
Tom Ogilvy




"zSplash" <zNOSPAMSplash@ gci.net wrote in message
...
I am trying to select cells in several sheets, if the user is in Sheet1

and
selects a cell in column A. I get a '1004' error ("Select method of Range
class failed") at Range("A" & Target.Row).Select. Can somebody help me?
Here is my code:

... If Target.Cells.Count = 1 Then
1: ' if they select a cell in Col 1, select complementary cell in

other
sheets
If Target.Column = 1 And Target.Value < "" Then
Sheets(3).Select
Range("A" & Target.Row).Select
Sheets(4).Range("A" & Target.Row).Sheets(5).Select
Sheets(1).Select
EndIf
EndIf
...

TIA




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Using Target.Row in other Sheets

Outstanding, Tom! Thanks so much.

st.

"Tom Ogilvy" wrote in message
...

You can only select on the activesheet.

On Error goto ErrHandler
Dim sh as Worksheet
Dim sAddr as String
if Target.Count 1 then exit sub
If Target.Column = 1 And Target.Value < "" Then
sAddr = target.Address
Application.ScreenUpdating = False
Application.EnableEvents = False
for each sh in worksheets(Array("sheet2","Sheet3","Sheet4","Sheet 5"))
sh.Activate
sh.Range(sAddr).Select
Next
me.activate

End if
ErrHandler
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub

--
Regards,
Tom Ogilvy




"zSplash" <zNOSPAMSplash@ gci.net wrote in message
...
I am trying to select cells in several sheets, if the user is in Sheet1

and
selects a cell in column A. I get a '1004' error ("Select method of

Range
class failed") at Range("A" & Target.Row).Select. Can somebody help me?
Here is my code:

... If Target.Cells.Count = 1 Then
1: ' if they select a cell in Col 1, select complementary cell in

other
sheets
If Target.Column = 1 And Target.Value < "" Then
Sheets(3).Select
Range("A" & Target.Row).Select
Sheets(4).Range("A" & Target.Row).Sheets(5).Select
Sheets(1).Select
EndIf
EndIf
...

TIA






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Using Target.Row in other Sheets

So, Tom, your code works wonderfully. Once. After that, none of the
worksheet_change event codes work. If I close the workbook, and re-open it,
they again work. What do you think?

st.

"zSplash" <zNOSPAMSplash@ gci.net wrote in message
...
Outstanding, Tom! Thanks so much.

st.

"Tom Ogilvy" wrote in message
...

You can only select on the activesheet.

On Error goto ErrHandler
Dim sh as Worksheet
Dim sAddr as String
if Target.Count 1 then exit sub
If Target.Column = 1 And Target.Value < "" Then
sAddr = target.Address
Application.ScreenUpdating = False
Application.EnableEvents = False
for each sh in worksheets(Array("sheet2","Sheet3","Sheet4","Sheet 5"))
sh.Activate
sh.Range(sAddr).Select
Next
me.activate

End if
ErrHandler
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub

--
Regards,
Tom Ogilvy




"zSplash" <zNOSPAMSplash@ gci.net wrote in message
...
I am trying to select cells in several sheets, if the user is in

Sheet1
and
selects a cell in column A. I get a '1004' error ("Select method of

Range
class failed") at Range("A" & Target.Row).Select. Can somebody help

me?
Here is my code:

... If Target.Cells.Count = 1 Then
1: ' if they select a cell in Col 1, select complementary cell in

other
sheets
If Target.Column = 1 And Target.Value < "" Then
Sheets(3).Select
Range("A" & Target.Row).Select
Sheets(4).Range("A" & Target.Row).Sheets(5).Select
Sheets(1).Select
EndIf
EndIf
...

TIA










  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Using Target.Row in other Sheets

Sounds like events have been disabled, however, I re-enable events in the
error handler. Note that I do not jump out of the sub before getting to the
error handler. If you added code such as

Exit Sub '<== added code? -- no no
ErrHandler
Application.ScreenUpdating =True
Application.EnableEvents = True
End sub

as one would normally do with an error handler, then this is incorrect. I
intentionally fall through the error handler on every execution of the code
so events are always enabled:

On Error goto ErrHandler
Dim sh as Worksheet
Dim sAddr as String
if Target.Count 1 then exit sub
If Target.Column = 1 And Target.Value < "" Then
sAddr = target.Address
Application.ScreenUpdating = False
Application.EnableEvents = False
for each sh in worksheets(Array("sheet2","Sheet3","Sheet4","Sheet 5"))
sh.Activate
sh.Range(sAddr).Select
Next
me.activate

End if
ErrHandler
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub


Other than that, I can't say why events are not being enabled. However,
since I would see this as sheet level code, I don't think you really need to
disable events, so you could comment out that line:

On Error goto ErrHandler
Dim sh as Worksheet
Dim sAddr as String
if Target.Count 1 then exit sub
If Target.Column = 1 And Target.Value < "" Then
sAddr = target.Address
Application.ScreenUpdating = False
'Application.EnableEvents = False ' <= comment out
for each sh in worksheets(Array("sheet2","Sheet3","Sheet4","Sheet 5"))
sh.Activate
sh.Range(sAddr).Select
Next
me.activate

End if
ErrHandler
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub


If you have duplicated this code on multiple sheets, then you need to
disable events or you will get into a recursive situation.

--
Regards,
Tom Ogilvy



"zSplash" <zNOSPAMSplash@ gci.net wrote in message
...
So, Tom, your code works wonderfully. Once. After that, none of the
worksheet_change event codes work. If I close the workbook, and re-open

it,
they again work. What do you think?

st.

"zSplash" <zNOSPAMSplash@ gci.net wrote in message
...
Outstanding, Tom! Thanks so much.

st.

"Tom Ogilvy" wrote in message
...

You can only select on the activesheet.

On Error goto ErrHandler
Dim sh as Worksheet
Dim sAddr as String
if Target.Count 1 then exit sub
If Target.Column = 1 And Target.Value < "" Then
sAddr = target.Address
Application.ScreenUpdating = False
Application.EnableEvents = False
for each sh in worksheets(Array("sheet2","Sheet3","Sheet4","Sheet 5"))
sh.Activate
sh.Range(sAddr).Select
Next
me.activate

End if
ErrHandler
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub

--
Regards,
Tom Ogilvy




"zSplash" <zNOSPAMSplash@ gci.net wrote in message
...
I am trying to select cells in several sheets, if the user is in

Sheet1
and
selects a cell in column A. I get a '1004' error ("Select method of

Range
class failed") at Range("A" & Target.Row).Select. Can somebody help

me?
Here is my code:

... If Target.Cells.Count = 1 Then
1: ' if they select a cell in Col 1, select complementary cell

in
other
sheets
If Target.Column = 1 And Target.Value < "" Then
Sheets(3).Select
Range("A" & Target.Row).Select
Sheets(4).Range("A" & Target.Row).Sheets(5).Select
Sheets(1).Select
EndIf
EndIf
...

TIA










  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Using Target.Row in other Sheets

Thank you, Tom.

st.

"Tom Ogilvy" wrote in message
...
Sounds like events have been disabled, however, I re-enable events in the
error handler. Note that I do not jump out of the sub before getting to

the
error handler. If you added code such as

Exit Sub '<== added code? -- no no
ErrHandler
Application.ScreenUpdating =True
Application.EnableEvents = True
End sub

as one would normally do with an error handler, then this is incorrect. I
intentionally fall through the error handler on every execution of the

code
so events are always enabled:

On Error goto ErrHandler
Dim sh as Worksheet
Dim sAddr as String
if Target.Count 1 then exit sub
If Target.Column = 1 And Target.Value < "" Then
sAddr = target.Address
Application.ScreenUpdating = False
Application.EnableEvents = False
for each sh in worksheets(Array("sheet2","Sheet3","Sheet4","Sheet 5"))
sh.Activate
sh.Range(sAddr).Select
Next
me.activate

End if
ErrHandler
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub


Other than that, I can't say why events are not being enabled. However,
since I would see this as sheet level code, I don't think you really need

to
disable events, so you could comment out that line:

On Error goto ErrHandler
Dim sh as Worksheet
Dim sAddr as String
if Target.Count 1 then exit sub
If Target.Column = 1 And Target.Value < "" Then
sAddr = target.Address
Application.ScreenUpdating = False
'Application.EnableEvents = False ' <= comment out
for each sh in worksheets(Array("sheet2","Sheet3","Sheet4","Sheet 5"))
sh.Activate
sh.Range(sAddr).Select
Next
me.activate

End if
ErrHandler
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub


If you have duplicated this code on multiple sheets, then you need to
disable events or you will get into a recursive situation.

--
Regards,
Tom Ogilvy



"zSplash" <zNOSPAMSplash@ gci.net wrote in message
...
So, Tom, your code works wonderfully. Once. After that, none of the
worksheet_change event codes work. If I close the workbook, and re-open

it,
they again work. What do you think?

st.

"zSplash" <zNOSPAMSplash@ gci.net wrote in message
...
Outstanding, Tom! Thanks so much.

st.

"Tom Ogilvy" wrote in message
...

You can only select on the activesheet.

On Error goto ErrHandler
Dim sh as Worksheet
Dim sAddr as String
if Target.Count 1 then exit sub
If Target.Column = 1 And Target.Value < "" Then
sAddr = target.Address
Application.ScreenUpdating = False
Application.EnableEvents = False
for each sh in

worksheets(Array("sheet2","Sheet3","Sheet4","Sheet 5"))
sh.Activate
sh.Range(sAddr).Select
Next
me.activate

End if
ErrHandler
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub

--
Regards,
Tom Ogilvy




"zSplash" <zNOSPAMSplash@ gci.net wrote in message
...
I am trying to select cells in several sheets, if the user is in

Sheet1
and
selects a cell in column A. I get a '1004' error ("Select method

of
Range
class failed") at Range("A" & Target.Row).Select. Can somebody

help
me?
Here is my code:

... If Target.Cells.Count = 1 Then
1: ' if they select a cell in Col 1, select complementary

cell
in
other
sheets
If Target.Column = 1 And Target.Value < "" Then
Sheets(3).Select
Range("A" & Target.Row).Select
Sheets(4).Range("A" & Target.Row).Sheets(5).Select
Sheets(1).Select
EndIf
EndIf
...

TIA












  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Using Target.Row in other Sheets

BTW, Tom, you were right. I had "opted out of the error handler". That
fixed everything.

st.



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
Target.Value lehigh46 Excel Worksheet Functions 2 April 1st 08 01:01 PM
Target cell reference moves when target is cut and pasted Illya Teideman Excel Discussion (Misc queries) 5 May 31st 07 11:34 AM
target.value Curt Excel Discussion (Misc queries) 7 April 21st 07 02:30 AM
Target Param Excel Worksheet Functions 1 March 16th 06 08:13 PM
Target value, Next cell D.Parker Excel Discussion (Misc queries) 3 May 4th 05 09:00 PM


All times are GMT +1. The time now is 12:02 PM.

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

About Us

"It's about Microsoft Excel"