+ Reply to Thread
Results 1 to 7 of 7

run macro automatically

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    01-14-2004
    Location
    India
    MS-Off Ver
    365
    Posts
    264

    run macro automatically

    Hello,
    Is there any way I can run a macro depends on the value of a cell.

    For Eg: If the value in A1=1 then run macro5, if the value in A1=2 then run macro3

    Thanks in Advance
    Toms

  2. #2
    Forum Contributor
    Join Date
    03-13-2005
    Posts
    6,195
    Quote Originally Posted by SMILE
    Hello,
    Is there any way I can run a macro depends on the value of a cell.

    For Eg: If the value in A1=1 then run macro5, if the value in A1=2 then run macro3

    Thanks in Advance
    Toms
    Hi,

    In the Worksheet code window,
    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
    If Target.Address = "$A$1" Then
    If Target.Value = 1 Then
     Module1.macro1
     Else
     If Target.Value = 2 Then
     Module1.macro2
     End If
    End If
    End If
    End Sub
    and in Module1
    Sub macro1()
    MsgBox 1
    End Sub
    
    Sub macro2()
    MsgBox 2
    End Sub
    hth
    ---
    Si fractum non sit, noli id reficere.

  3. #3
    Forum Contributor
    Join Date
    01-14-2004
    Location
    India
    MS-Off Ver
    365
    Posts
    264

    Thanks

    Bryan
    you are genius !!!!!!!!!!!!!
    Thanks a lot... I got what I wanted...

    Toms

  4. #4
    Forum Contributor
    Join Date
    03-13-2005
    Posts
    6,195
    Quote Originally Posted by SMILE
    Bryan
    Thanks a lot... I got what I wanted...

    Toms
    Good to see it worked for you, and thanks for the response.

    ---

  5. #5
    Forum Contributor
    Join Date
    01-14-2004
    Location
    India
    MS-Off Ver
    365
    Posts
    264

    Hello

    Bryan
    just to know, what the following line does in the program ????

    If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub

    thanks
    toms

  6. #6
    Forum Contributor
    Join Date
    03-13-2005
    Posts
    6,195
    Quote Originally Posted by SMILE
    Bryan
    just to know, what the following line does in the program ????

    If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub

    thanks
    toms
    Hi,

    it checks to see if more than a single cell triggered the code, or if the cell is empty, in either case nothing is required to happen.

    hth
    ---

  7. #7
    Forum Contributor
    Join Date
    01-14-2004
    Location
    India
    MS-Off Ver
    365
    Posts
    264

    thank you

    thank you!!!!!!!!!!!!!!!

+ 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