Results 1 to 2 of 2

Thread: trigger vba or macro when leaving a cell...

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Location
    Neenah, WI USA
    Posts
    95

    trigger vba or macro when leaving a cell...

    This should be easy, and maybe I'm just missing something, but I want to run a macro or vba code when the user enters something into a specific cell and then moves to the next cell.

    What is happening is that the user pastes a block of text into a cell, and it seems to really screw up the cell format. So when they move on to the next cell, I want to run a macro to reformat the cell I just left. In reality I have 4 specific cells they can enter data into, the rest are locked. The macro I have reformats all 4 cells, which is fine. I just can't figure out how to trigger it other than using a button...

    THanks
    Steve

  2. #2
    Lively Member TheFIDDLER's Avatar
    Join Date
    May 2002
    Location
    here and there and far away
    Posts
    126
    something like this would work for you...
    store this as code in your worksheet module

    VB Code:
    1. Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
    2.  
    3.     If ActiveCell = Range("A1") Then
    4.         With Selection.Interior
    5.         .ColorIndex = 10
    6.         .Pattern = xlSolid
    7.         End With
    8.     ElseIf ActiveCell = Range("A2") Then
    9.           With Selection.Interior
    10.         .ColorIndex = 15
    11.         .Pattern = xlSolid
    12.         End With
    13.     Else
    14.         With Selection.Font
    15.         .Name = "Arial"
    16.         .Size = 14
    17.         End With
    18.     End If
    19. End Sub
    -----
    #VBA, VB 6 Professional Edition, Office XP Developper. Excel 97, Excel 2000, Excel XP

    I miss my VIC 20.
    Never should have upgraded to my commodore 64. ...

Posting Permissions

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



Click Here to Expand Forum to Full Width