+ Reply to Thread
Results 1 to 4 of 4

VBA to execute macro on A column cell selection

Hybrid View

shiva_reshs VBA to execute macro on A... 09-04-2014, 05:47 AM
sweep Re: VBA to execute macro on A... 09-04-2014, 05:57 AM
lancer102rus Re: VBA to execute macro on A... 09-04-2014, 05:57 AM
shiva_reshs Re: VBA to execute macro on A... 09-04-2014, 06:06 AM
  1. #1
    Forum Contributor
    Join Date
    07-17-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    715

    VBA to execute macro on A column cell selection

    Hi,

    I have below code, which execute Now() code when user hit ctrl C in any of the 3 sheet noted in the code.
    But how can I restric the code to execute only when current sheet is one of three below with cell selection only in column A and not in another column.

    Sub Time()
    
    Dim cursht As String
    cursht = ActiveSheet.Name
       If cursht = "AB" Or cursht = "BC" Or cursht = "DC" Then
          ActiveCell.Offset(0, 15).Value = Now()
    ActiveCell.Copy
       Else
    Selection.Copy
       End If
    
    End Sub
    Keep the Forum clean :


    1. Use [ code ] code tags [ /code ]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    2. Show appreciation to those who have helped you by clicking * Add Reputation below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

  2. #2
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,454

    Re: VBA to execute macro on A column cell selection

    Does this help?

    Sub Time()
    
    Dim cursht As String
    cursht = ActiveSheet.Name
       If (cursht = "AB" Or cursht = "BC" Or cursht = "DC") And Not Intersect(ActiveCell, Range("A:A")) Is Nothing Then
          ActiveCell.Offset(0, 15).Value = Now()
    ActiveCell.Copy
       Else
    Selection.Copy
       End If
    
    Application.CutCopyMode = False
    
    End Sub
    Last edited by sweep; 09-04-2014 at 06:01 AM. Reason: overcomplecated
    Rule 1: Never merge cells
    Rule 2: See rule 1

    "Tomorrow I'm going to be famous. All I need is a tennis racket and a hat".

  3. #3
    Forum Contributor lancer102rus's Avatar
    Join Date
    04-02-2014
    Location
    Ufa
    MS-Off Ver
    Excel 2010, 2013
    Posts
    252

    Re: VBA to execute macro on A column cell selection

    ...If (cursht = "AB" Or cursht = "BC" Or cursht = "DC") and (ActiveCell.Column = 1) Then...

  4. #4
    Forum Contributor
    Join Date
    07-17-2012
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    715

    Re: VBA to execute macro on A column cell selection

    Thanks.. Both code works well.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. To execute macro whenever there's input in one of the column
    By Kehjz in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-18-2014, 10:02 AM
  2. Execute a Macro upon user selection or cell entry
    By blakemiller in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-29-2012, 12:22 AM
  3. Execute Cell with a Macro (timer)
    By flds in forum Excel General
    Replies: 6
    Last Post: 05-13-2010, 07:26 AM
  4. Replies: 1
    Last Post: 03-02-2010, 01:23 PM
  5. On Cell change, execute macro
    By des_wes in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-19-2007, 07:01 PM

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