Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Hiding cells in another worksheet

Dear all

I have the following simple macro in a worksheet object to hide
certain columns whenever a change is made to a worksheet.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim cell As Range

For Each cell In Range("dDataReq1")
Columns(cell.Column).Hidden = False
If cell.Value = 0 Then
Columns(cell.Column).Hidden = True
End If
Next cell

End Sub

The problem I have is that when the range "dDataReq1" is in another
worksheet, and I want the columns in that worksheet to be hidden, I
get the following error:

method "Range" of object "_worksheet" failed.

It is obvious that my method of referencing the range "dDataReq1" is
ineffective when "dDataReq1" is in a different worksheet, but I can't
seem to find a way around it.

Can anybody help with this?

Thanks

JT
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Hiding cells in another worksheet

One way:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim rCell As Range

For Each rCell In Me.Parent.Names("dDataReq1").RefersToRange
rCell.EntireColumn.Hidden = (rCell.Value = 0)
Next rCell
End Sub


In article
,
JT wrote:

Dear all

I have the following simple macro in a worksheet object to hide
certain columns whenever a change is made to a worksheet.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim cell As Range

For Each cell In Range("dDataReq1")
Columns(cell.Column).Hidden = False
If cell.Value = 0 Then
Columns(cell.Column).Hidden = True
End If
Next cell

End Sub

The problem I have is that when the range "dDataReq1" is in another
worksheet, and I want the columns in that worksheet to be hidden, I
get the following error:

method "Range" of object "_worksheet" failed.

It is obvious that my method of referencing the range "dDataReq1" is
ineffective when "dDataReq1" is in a different worksheet, but I can't
seem to find a way around it.

Can anybody help with this?

Thanks

JT

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Hiding cells in another worksheet

Thanks, works a treat.

Thanks for also tidying up the rest of the code.
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
Hiding a Worksheet oceanmist Excel Discussion (Misc queries) 3 June 14th 07 04:48 PM
Hiding a Worksheet Marek Excel Programming 6 March 28th 07 08:42 PM
Hiding a Worksheet Tom Ogilvy Excel Programming 0 March 28th 07 12:01 AM
Hiding a Worksheet Vergel Adriano Excel Programming 0 March 27th 07 11:46 PM
Hiding a Worksheet Tom Ogilvy Excel Programming 0 March 27th 07 11:21 PM


All times are GMT +1. The time now is 04:51 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"