PC Review


Reply
Thread Tools Rate Thread

Do function on worksheet open

 
 
eli.tallman@gmail.com
Guest
Posts: n/a
 
      7th Dec 2007
I am trying to set a function to run when my worksheet is open. I
have found the workbook_open() function and if I have to I suppose I
can use this to do what I am trying to do. I want a process to run
when the worksheet is first opened that will search a specific column
for a specific value, and if found, hide the rows the value is found
on. I currently use this code to hid the rows when the value is
entered initially:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("M:M")) Is Nothing Then
If Target.Value = "Y" Then Target.EntireRow.Hidden = True
End If
End Sub

I want this new functionality so that if the hidden data is unhidden,
I do not have to re-hide it manually. I would like Excel to do this
for me when the file is first opened.

What is the best way to do this?

Thanks in advance.
 
Reply With Quote
 
 
 
 
JLGWhiz
Guest
Posts: n/a
 
      8th Dec 2007
With the worksheet_change procedure, each row will be hidden as a "Y" is
entered in column "M". With Workbook_Open or Worksheet_Activate you would
need to evaluate the entire column for all "Y" entries and hide each one as
found.

Private Sub [Workbook_Open] or [Worksheet_Activate] () 'Pick one
Dim c As Range
With Worksheets(?) 'enter the sheet name or index number
For Each c In .Range("M2:M" & .Cells(Rows.Count, 13).End(xlUp)).Row
If c.Value = "Y" Then
c.EntireRow.Hidden = True
End If
Next
End With
End Sub

This is untested code. Try it on a copy before using in original.


"(E-Mail Removed)" wrote:

> I am trying to set a function to run when my worksheet is open. I
> have found the workbook_open() function and if I have to I suppose I
> can use this to do what I am trying to do. I want a process to run
> when the worksheet is first opened that will search a specific column
> for a specific value, and if found, hide the rows the value is found
> on. I currently use this code to hid the rows when the value is
> entered initially:
>
> Private Sub Worksheet_Change(ByVal Target As Range)
> If Not Intersect(Target, Range("M:M")) Is Nothing Then
> If Target.Value = "Y" Then Target.EntireRow.Hidden = True
> End If
> End Sub
>
> I want this new functionality so that if the hidden data is unhidden,
> I do not have to re-hide it manually. I would like Excel to do this
> for me when the file is first opened.
>
> What is the best way to do this?
>
> Thanks in advance.
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
calling a worksheet function from another worksheet in same workbo Liz Microsoft Excel Programming 5 23rd Jun 2008 06:16 PM
Unable to open worksheet when called through a function =?Utf-8?B?em9kZGlheA==?= Microsoft Excel Programming 3 3rd Aug 2007 04:18 AM
Reference the worksheet from a multiple worksheet range function ( =?Utf-8?B?REJpY2tlbA==?= Microsoft Excel Worksheet Functions 1 28th May 2005 03:49 AM
formula/function to copy from worksheet to worksheet =?Utf-8?B?SmVu?= Microsoft Excel Programming 5 11th Jan 2005 08:22 PM
Need function to insert worksheet name into a cell of that worksheet. August Meduna Microsoft Excel Misc 2 9th Oct 2004 12:57 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:05 PM.