Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
DEE DEE is offline
external usenet poster
 
Posts: 250
Default Select Named Range in Worksheet

Hi,

I'm trying to add code to an option button on a worksheet that hides rows on
its worksheet, plus hides columns on another worksheet, plus hides rows on
another worksheet.

I have named my ranges, which I refer to in the code. I tried many
variations that I have found in the last few hours in this group and other
places in the Internet, but as soon as I try to hide the columns/rows on a
worksheet other than the active one that contains the option button, I end up
with errors.

Here is my code: Any help is really appreciated!

Private Sub OptionButton1_Click()

Application.ScreenUpdating = False

With ThisWorkbook.Worksheets("Data")
Range("FebtoDec").Select
Selection.EntireRow.Hidden = True
End With

With Worksheets("Distribution").Range("DistributionFebt oDec")
.EntireColumn.Hidden = True
End With

With Worksheets("Summary").Range("SummaryFebtoDec")
.EntireRow.Hidden = True
End With

Application.ScreenUpdating = True

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,069
Default Select Named Range in Worksheet

You can't select cells that aren't on the active sheet. Your code to select a
range on the Data sheet fails if it's not the active sheet when you run the
nacro. Try this slight variation:

Private Sub OptionButton1_Click()
Application.ScreenUpdating = False
With ThisWorkbook.Worksheets("Data").Range("FebtoDec")
.EntireRow.Hidden = True
End With
With Worksheets("Distribution").Range("DistributionFebt oDec")
.EntireColumn.Hidden = True
End With
With Worksheets("Summary").Range("SummaryFebtoDec")
.EntireRow.Hidden = True
End With
Application.ScreenUpdating = True
End Sub


"Dee" wrote:

Hi,

I'm trying to add code to an option button on a worksheet that hides rows on
its worksheet, plus hides columns on another worksheet, plus hides rows on
another worksheet.

I have named my ranges, which I refer to in the code. I tried many
variations that I have found in the last few hours in this group and other
places in the Internet, but as soon as I try to hide the columns/rows on a
worksheet other than the active one that contains the option button, I end up
with errors.

Here is my code: Any help is really appreciated!

Private Sub OptionButton1_Click()

Application.ScreenUpdating = False

With ThisWorkbook.Worksheets("Data")
Range("FebtoDec").Select
Selection.EntireRow.Hidden = True
End With

With Worksheets("Distribution").Range("DistributionFebt oDec")
.EntireColumn.Hidden = True
End With

With Worksheets("Summary").Range("SummaryFebtoDec")
.EntireRow.Hidden = True
End With

Application.ScreenUpdating = True

End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
DEE DEE is offline
external usenet poster
 
Posts: 250
Default Select Named Range in Worksheet

Thanks, Tom. This worked perfectly. If I have another range in the same
workbook, would this code be correct? Thanks again.

Private Sub OptionButton1_Click()
Application.ScreenUpdating = False
With ThisWorkbook.Worksheets("Data").Range("FebtoDec")

.EntireRow.Hidden = True
Range("AnotherNamedRange").EntireRow.Hidden = True

End With




"Tom Hutchins" wrote:

You can't select cells that aren't on the active sheet. Your code to select a
range on the Data sheet fails if it's not the active sheet when you run the
nacro. Try this slight variation:

Private Sub OptionButton1_Click()
Application.ScreenUpdating = False
With ThisWorkbook.Worksheets("Data").Range("FebtoDec")
.EntireRow.Hidden = True
End With
With Worksheets("Distribution").Range("DistributionFebt oDec")
.EntireColumn.Hidden = True
End With
With Worksheets("Summary").Range("SummaryFebtoDec")
.EntireRow.Hidden = True
End With
Application.ScreenUpdating = True
End Sub


"Dee" wrote:

Hi,

I'm trying to add code to an option button on a worksheet that hides rows on
its worksheet, plus hides columns on another worksheet, plus hides rows on
another worksheet.

I have named my ranges, which I refer to in the code. I tried many
variations that I have found in the last few hours in this group and other
places in the Internet, but as soon as I try to hide the columns/rows on a
worksheet other than the active one that contains the option button, I end up
with errors.

Here is my code: Any help is really appreciated!

Private Sub OptionButton1_Click()

Application.ScreenUpdating = False

With ThisWorkbook.Worksheets("Data")
Range("FebtoDec").Select
Selection.EntireRow.Hidden = True
End With

With Worksheets("Distribution").Range("DistributionFebt oDec")
.EntireColumn.Hidden = True
End With

With Worksheets("Summary").Range("SummaryFebtoDec")
.EntireRow.Hidden = True
End With

Application.ScreenUpdating = True

End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,069
Default Select Named Range in Worksheet

You can't embed the statement for "AnotherNamedRange" inside the With...End
With construction for a different range. Just add a With...End With
construction for the additional range, similar to the others:

With ThisWorkbook.Worksheets("Data").Range("AnotherName dRange")
.EntireRow.Hidden = True
End With

Hutch

"Dee" wrote:

Thanks, Tom. This worked perfectly. If I have another range in the same
workbook, would this code be correct? Thanks again.

Private Sub OptionButton1_Click()
Application.ScreenUpdating = False
With ThisWorkbook.Worksheets("Data").Range("FebtoDec")

.EntireRow.Hidden = True
Range("AnotherNamedRange").EntireRow.Hidden = True

End With




"Tom Hutchins" wrote:

You can't select cells that aren't on the active sheet. Your code to select a
range on the Data sheet fails if it's not the active sheet when you run the
nacro. Try this slight variation:

Private Sub OptionButton1_Click()
Application.ScreenUpdating = False
With ThisWorkbook.Worksheets("Data").Range("FebtoDec")
.EntireRow.Hidden = True
End With
With Worksheets("Distribution").Range("DistributionFebt oDec")
.EntireColumn.Hidden = True
End With
With Worksheets("Summary").Range("SummaryFebtoDec")
.EntireRow.Hidden = True
End With
Application.ScreenUpdating = True
End Sub


"Dee" wrote:

Hi,

I'm trying to add code to an option button on a worksheet that hides rows on
its worksheet, plus hides columns on another worksheet, plus hides rows on
another worksheet.

I have named my ranges, which I refer to in the code. I tried many
variations that I have found in the last few hours in this group and other
places in the Internet, but as soon as I try to hide the columns/rows on a
worksheet other than the active one that contains the option button, I end up
with errors.

Here is my code: Any help is really appreciated!

Private Sub OptionButton1_Click()

Application.ScreenUpdating = False

With ThisWorkbook.Worksheets("Data")
Range("FebtoDec").Select
Selection.EntireRow.Hidden = True
End With

With Worksheets("Distribution").Range("DistributionFebt oDec")
.EntireColumn.Hidden = True
End With

With Worksheets("Summary").Range("SummaryFebtoDec")
.EntireRow.Hidden = True
End With

Application.ScreenUpdating = True

End Sub

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 select only cells containing values within named range Code Numpty Excel Programming 2 November 25th 08 07:36 AM
How to select named range list dependent on another selection Matt Brown[_2_] Excel Programming 2 June 27th 07 10:34 PM
how to select ALL named shapes in range Corey Excel Programming 1 August 25th 06 01:14 AM
Compare a selected Range with a Named range and select cells that do not exist PCLIVE Excel Programming 1 October 18th 05 07:09 PM
How do I use the data in a named field to select a worksheet tab . Graham Excel Discussion (Misc queries) 1 August 23rd 05 04:05 PM


All times are GMT +1. The time now is 05:38 AM.

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"