Results 1 to 4 of 4
  1. #1
    Star Lounger
    Join Date
    Feb 2006
    Posts
    71
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Kick off macros (Excel2003)

    looking for a way to kickoff a macro when a cell is selected.
    Specific: Want to select a cell in column A(x) and have the macro copy cells A(x)-E(x) in that row to a specific location.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Kick off macros (Excel2003)

    Try the following:
    - Right-click the sheet tab.
    - Select View Code from the popup menu.
    - Type or copy the following code into the worksheet module that appears:
    <code>
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Not Intersect(ActiveCell, Range("A:A")) Is Nothing Then
    Application.EnableEvents = False
    ' Modify the destination as needed
    ActiveCell.Resize(1, 5).Copy Destination:=Range("L37")
    Application.EnableEvents = True
    End If
    End Sub
    </code>
    Change Range("L37") to the "specific location" where you want to copy to. It can be on another sheet too.
    The code will be run automatically if you select a cell in column A.

  3. #3
    Star Lounger
    Join Date
    Feb 2006
    Posts
    71
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Kick off macros (Excel2003)

    That code works. Is there code to 'Paste Special'?
    Define specific cell and 'paste special' it's FORMAT to another cell. Specifically it's color.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Kick off macros (Excel2003)

    If you want to copy all formatting:
    <code>
    Range("C1").Copy
    Range("F5").PasteSpecial Operation:=xlPasteFormats
    </code>
    If you only want to copy the fill color:
    <code>
    Range("F5").Interior.ColorIndex = Range("C1").Interior.ColorIndex
    </code>
    Or if you only want to copy the text color:
    <code>
    Range("F5").Font.ColorIndex = Range("C1").Font.ColorIndex
    </code>
    You can replace the source or target cell with ActiveCell to indicate the currently selected cell.

Posting Permissions

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