+ Reply to Thread
Results 1 to 3 of 3

Run Macro from Conditional Cell Change?

Hybrid View

  1. #1
    Registered User
    Join Date
    03-16-2004
    Posts
    23

    Run Macro from Conditional Cell Change?

    Hello,
    I'd like to run a macro when a cell value changes conditionally, based on values entered into precedent cells (so that I'm not actually selecting or typing into the cell in focus) - is this possible? Ideally, I'd like to have a message box pop up, but could also insert a comment or autoshape. I can't find a way to get VBA to recognize such a change.
    Thank you for your help!

  2. #2
    Forum Contributor
    Join Date
    09-04-2006
    Location
    Yorkshire, England
    Posts
    267
    Hey,


    put this in the Sheet 1 module in the visual basic editor:


    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Intersect(Target, Range("a1")) Is Nothing Then
    Exit Sub
    Else
    Range("B1").Select
    With Selection.Interior
    .ColorIndex = 46
    .Pattern = xlSolid
    End With
    End If
    End Sub


    Change to suit your needs.

    Message box code:

    MsgBox "Text", , "Title"

    Remeber to save your workbook and re open it first


    Hope it helps
    Last edited by JR@SGC; 11-14-2006 at 05:04 AM.
    JR
    Versions
    Mac OS X 'Leopard'
    Mac MS Office Excel 2004
    Windows XP
    MS Excel 2002
    MS Excel 2003

  3. #3
    Registered User
    Join Date
    03-16-2004
    Posts
    23
    Thanks for the reply...I'm not sure I fully understand the Intersect method, but it still seems that I have to click on A1 to make a change and execute the code. What I'm looking to do, for example, is put a formula in A1 such as =IF(E1=5, 1, "")
    and then I only want to change E1, with the code something like this:

    Private Sub Worksheet_Change(ByVal Target As Range)

    Target = Range("A1")
    If Target <> 1 Then
    Exit Sub
    Else
    UserForm1.Show

    End If
    End Sub

    Would something like this be possible? Thanks!!

+ 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