Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / January 2008

Tip: Looking for answers? Try searching our database.

Selecting a range after activating a worksheet

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
JPCPA - 23 Jan 2008 17:56 GMT
I have a file with 10 diffrent tabs.  Depending on the option button chosen
on the first tab, certain columns need to be hiddein or revealed on a second
tab.  I'm getting an 'application-defined or object-defined error' when it
tries to select a range on the newly activated worksheet.  Can someone tell
me what I'm doing wrong?

   If Opt1 = True Then
       Range("SampleStrat").EntireRow.Hidden = False
       Range("UnstratSample").EntireRow.Hidden = True
       Worksheets("Sample Evaluation").Activate
       Range("StratEval").Select                      (This is where it
errors out)
       Selection.EntireColumn.Hidden = False
       Range("UnstratEval").Select
       Selection.EntireColumn.Hidden = True
       Worksheets("Sample Calc").Activate
Signature

JP

JPCPA - 23 Jan 2008 20:40 GMT
Never mind!  I figured out my error.

Signature

JP

Conan Kelly - 23 Jan 2008 21:28 GMT
JPCPA,

Just out of curiosity, what was your error.

I briefly looked at your post to see if I could figure it out.

Thanks,

Conan

> Never mind!  I figured out my error.
JPCPA - 23 Jan 2008 21:44 GMT
The initial macro is being called from an option button.  when I created the
macro, it put it on the  excel object for sheet1.  I was trying to activate
sheet2 and hide columns on sheet2 from here.  When I put the piece of the
macro to hide the columns for sheet2 in a module instead, it worked.   I end
up with two macros instead of one, as shown below.  I'm sure there's probably
a better way to do things, but I'm not that familiar with programming in
Excel.

Private Sub opt1_Click()
If Opt1 = True Then
   ActiveSheet.Unprotect
   Range("SampleStrat").EntireRow.Hidden = False
   Range("UnstratSample").EntireRow.Hidden = True
   Application.Run ("Module1.HideUnstrat")
End If
End Sub

Sub HideStrat()
   Sheets("Sample Evaluation").Select
   ActiveSheet.Unprotect
   Columns("B:D").Select
   Selection.EntireColumn.Hidden = True
   Columns("E:E").Select
   Selection.EntireColumn.Hidden = False
   ActiveSheet.Protect Contents:=True, Scenarios:=True,
AllowFormattingCells:=True
   Worksheets("Sample Calc").Select
   ActiveSheet.Protect Contents:=True, Scenarios:=True,
AllowFormattingCells:=True
End Sub

Signature

JP

> JPCPA,
>
[quoted text clipped - 7 lines]
>
> > Never mind!  I figured out my error.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.