+ Reply to Thread
Results 1 to 5 of 5

Starting a macro with the IF function

  1. #1
    THW
    Guest

    Starting a macro with the IF function

    Hi there,

    is there any way to start a macro, once the contition of the if-function in
    the worksheet turns true???

    greetings and thankst

    THW

  2. #2
    Bob Phillips
    Guest

    Re: Starting a macro with the IF function

    No, but you could use event code to monitor the cell

    Private Sub Worksheet_Change(ByVal Target As Range)

    On Error GoTo ws_exit:
    Application.EnableEvents = False
    If Target.Address = "$H$1" Then
    With Target
    'do your stuff
    End With
    End If

    ws_exit:
    Application.EnableEvents = True
    End Sub

    'This is worksheet event code, which means that it needs to be
    'placed in the appropriate worksheet code module, not a standard
    'code module. To do this, right-click on the sheet tab, select
    'the View Code option from the menu, and paste the code in.

    --
    HTH

    Bob Phillips

    "THW" <[email protected]> wrote in message
    news:[email protected]...
    > Hi there,
    >
    > is there any way to start a macro, once the contition of the if-function

    in
    > the worksheet turns true???
    >
    > greetings and thankst
    >
    > THW




  3. #3
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile

    Good afternoon Thw

    A cell cannot kick off a macro, but you could use an event procedure to do something when the cell changes - paste this code into your worksheet event pane and replace my msgbox with your code. And remember that my code is checking for the value of cell A1 being false - your post doesn't state which cell you want to watch.

    Private Sub Worksheet_Calculate()
    If Range("A1") = True Then
    MsgBox "Cell A1 is true."
    End If
    End Sub

    HTH

    DominicB

  4. #4
    THW
    Guest

    Re: Starting a macro with the IF function

    hi dominicb

    thank you for your reply, but my problem is not to be notified if the value
    of a cell IS true, i need to be notified WHEN it's value changes to true

    greetings
    THW

    "dominicb" wrote:

    >
    > Good afternoon Thw
    >
    > A cell cannot kick off a macro, but you could use an event procedure to
    > do something when the cell changes - paste this code into your worksheet
    > event pane and replace my msgbox with your code. And remember that my
    > code is checking for the value of cell A1 being false - your post
    > doesn't state which cell you want to watch.
    >
    > Private Sub Worksheet_Calculate()
    > If Range("A1") = True Then
    > MsgBox "Cell A1 is true."
    > End If
    > End Sub
    >
    > HTH
    >
    > DominicB
    >
    >
    > --
    > dominicb
    > ------------------------------------------------------------------------
    > dominicb's Profile: http://www.excelforum.com/member.php...o&userid=18932
    > View this thread: http://www.excelforum.com/showthread...hreadid=380107
    >
    >


  5. #5
    Bob Phillips
    Guest

    Re: Starting a macro with the IF function

    I'll try again specifically

    Private Sub Worksheet_Change(ByVal Target As Range)

    On Error GoTo ws_exit:
    Application.EnableEvents = False
    If Target.Address = "$H$1" Then
    With Target
    if .value then
    Msgbox "true"
    endif
    End With
    End If

    ws_exit:
    Application.EnableEvents = True
    End Sub

    'This is worksheet event code, which means that it needs to be
    'placed in the appropriate worksheet code module, not a standard
    'code module. To do this, right-click on the sheet tab, select
    'the View Code option from the menu, and paste the code in.



    --
    HTH

    Bob Phillips

    "THW" <[email protected]> wrote in message
    news:[email protected]...
    > hi dominicb
    >
    > thank you for your reply, but my problem is not to be notified if the

    value
    > of a cell IS true, i need to be notified WHEN it's value changes to true
    >
    > greetings
    > THW
    >
    > "dominicb" wrote:
    >
    > >
    > > Good afternoon Thw
    > >
    > > A cell cannot kick off a macro, but you could use an event procedure to
    > > do something when the cell changes - paste this code into your worksheet
    > > event pane and replace my msgbox with your code. And remember that my
    > > code is checking for the value of cell A1 being false - your post
    > > doesn't state which cell you want to watch.
    > >
    > > Private Sub Worksheet_Calculate()
    > > If Range("A1") = True Then
    > > MsgBox "Cell A1 is true."
    > > End If
    > > End Sub
    > >
    > > HTH
    > >
    > > DominicB
    > >
    > >
    > > --
    > > dominicb
    > > ------------------------------------------------------------------------
    > > dominicb's Profile:

    http://www.excelforum.com/member.php...o&userid=18932
    > > View this thread:

    http://www.excelforum.com/showthread...hreadid=380107
    > >
    > >




+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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