+ Reply to Thread
Results 1 to 5 of 5

Macro Auto run

Hybrid View

Sazza Macro Auto run 11-25-2011, 07:01 AM
Steffen Thomsen Re: Macro Auto run 11-25-2011, 07:05 AM
Sazza Re: Macro Auto run 11-25-2011, 07:08 AM
Sazza Re: Macro Auto run 11-25-2011, 07:43 AM
Steffen Thomsen Re: Macro Auto run 11-25-2011, 08:06 AM
  1. #1
    Registered User
    Join Date
    02-20-2011
    Location
    Dublin
    MS-Off Ver
    Excel 2007
    Posts
    88

    Macro Auto run

    Hi Guys,

    New to Macros and VBA but ...

    I have a simple Macro to hide rows if a cell value is NO called "Sheet1.ZeroTest"

    this works but i have to run macro manually each time

    So i have looked around and see i need a Worksheet change function to call this automatically if the cell contents change to 'YES'

    I have something like this

    Private Sub Worksheet_Change(ByVal Target As Range)
     If Intersect(Target, Me.Range("C12")) Is Nothing Then Sheet1.ZeroTest
    End Sub
    But my problem is i dont know where to put this in order for it to work...

    I have the Macro in Sheet1, how do i add the auto run to sheet1 too

    thanks
    Saz
    Last edited by Sazza; 11-25-2011 at 08:28 AM. Reason: add code tags for newbie

  2. #2
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Macro Auto run

    You place this code in the sheet1 code module.

    When in excel right click on sheet1 and in the menu press "View code", here you insert the code

    Steffen Thomsen
    Please take time to read the forum rules

  3. #3
    Registered User
    Join Date
    02-20-2011
    Location
    Dublin
    MS-Off Ver
    Excel 2007
    Posts
    88

    Re: Macro Auto run

    Thanks ...

    So something like this :


    Private Sub Worksheet_Change(ByVal Target As Range)
     If Intersect(Target, Me.Range("C12")) Is Nothing Then
    
    Sub ZeroTest()
        If Range("C12").Value = "NO" Then
        Rows("14:15").EntireRow.Hidden = True
        Else
        End If
        
        If Range("C12").Value = "YES" Then
        Rows("14:15").EntireRow.Hidden = False
        Else
        End If
    
        End Sub
    Last edited by Sazza; 11-25-2011 at 08:29 AM.

  4. #4
    Registered User
    Join Date
    02-20-2011
    Location
    Dublin
    MS-Off Ver
    Excel 2007
    Posts
    88

    Re: Macro Auto run

    Never mind i got it going - thanks for your help

  5. #5
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Macro Auto run

    Then please mark your thread as solved according to the forum rules, and remember to put code tags around your code.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1