Consulting

Results 1 to 4 of 4

Thread: CAll a macro on entering data to a cell under a column

  1. #1

    CAll a macro on entering data to a cell under a column

    How to call a macro when a data is entered on any cell under column A of sheet1? ie if say 100 is written at cell A5 and pressed enter, a macro named Macro1 should fire. However A1 should be left as this is the header row.

  2. #2
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,776
    You could put something like this in the sheet's code module
    Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    If Target.Cells.Count = 1 And Target.Column = 1 Then
        Application.EnableEvents = False
        
        Call columnAMacro
        
        If Target.Address = "$A$5" And Target.Value = 100 Then
            Call Macro1
        End If
        
        Application.EnableEvents = False
    End If
    End Sub

  3. #3
    Thanks mike but I want to call a macro for every cell change in the column A.

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [VBA]Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    If Target.Cells.Count = 1 And Target.Column = 1 Then
    Application.EnableEvents = False
    Select Case Target
    Case Is = 100
    Call Macro1
    Case Is = 200
    Call Macro2
    Case Else
    'do nothing
    End Select
    Application.EnableEvents = False
    End If
    End Sub
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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