+ Reply to Thread
Results 1 to 2 of 2

How to trigger code execution?

Hybrid View

alwaysgo How to trigger code execution? 02-11-2008, 08:57 AM
VBA Noob alwaysgo, Please read and... 02-11-2008, 09:11 AM
  1. #1
    Registered User
    Join Date
    01-27-2008
    Posts
    11

    How to trigger code execution?

    How do I “trigger” vba code execution? Here is the problem and my sample code:

    Sub test()
    Range("A1").Select
    If ActiveCell = 1 Then
    ActiveCell.Offset(0, 1) = 2
    End If
    End Sub
    I know that I can go to Run Macro, select macro I created and it will run, but it is not good enough for my situation.

    I would like code to execute as soon as 1 is entered in A1 (as in above example.)

    I would appreciate any help, suggestions.
    Last edited by dominicb; 02-11-2008 at 09:06 AM.

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    alwaysgo,

    Please read and follow forum rules below. Your code as per wrap for you this time.

    Try the below code. Right click the sheet tab > select view code > then paste in the below
    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address(0, 0) = "A1" Then
        With Target
            If .Value = 1 Then
                   .Offset(0, 1) = 2
            End If
        End With
    End If
    
    End Sub
    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

+ 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