Consulting

Results 1 to 5 of 5

Thread: Help: Worksheet_change event disable "undo"?

  1. #1

    Help: Worksheet_change event disable "undo"?

    I have the following code in a worksheet to control change event, but when ever I try to copy cell by drag, i can not use autofill option: copy format only, or copy without format.

    When check the undo icon, it is faded. Do the code disable undo?

    is there anyway to use event code but still can use auto fill option?

    Please help

    Please help
    [vba]Private Function IsOpen(FileName As String) As Boolean
    ' Determine if a workbook is open or not
    Dim wb As Workbook
    For Each wb In Application.Workbooks
    If UCase(wb.Name) = UCase(FileName) Then
    IsOpen = True
    Exit Function
    End If
    Next wb
    IsOpen = False
    End Function
    Private Sub Worksheet_Change(ByVal Target As Excel.Range)

    On Error Resume Next
    If Not Intersect(Target, Range("A1:G300")) Is Nothing Then
    Range("I11").Interior.ColorIndex = 3
    End If
    If Not Intersect(Target, Range("J1:J6")) Is Nothing Then
    Range("I11").Interior.ColorIndex = 3
    End If
    If Not Intersect(Target, Range("L1:R300")) Is Nothing Then
    Range("I11").Interior.ColorIndex = 3
    End If
    End Sub
    [/vba]

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Any changes made by a macro cannot be undone with the Undo button or Ctrl Z. For this reason, it is sometimes desirable to build in an "Are you sure?" messagebox, before irreversible changes are made.
    e.g.
    [VBA]Sub DeleteRows()
    If Application.CountA(Selection.EntireRow) > 0 Then
    If MsgBox("Are you sure?", vbYesNo + vbDefaultButton2) = vbYes Then
    Selection.EntireRow.Delete
    End If
    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'

  3. #3
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Re your detailed question, Can you clarify what you are trying to do. I've not found any problems.
    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'

  4. #4
    my problems is:
    I make an event, when ever there is any changes in column A:A, cells I11 will be red.

    When I fill in Cell A1, then drag it to copy to all cell in A2:A12, it copy the format too. But I just want to copy number only,

    And because i can not undo, so can not use Auto Fill Option to adjust to: copy without format

  5. #5
    This is normal behaviour, don't drag, if you don't want it red.
    Or just reset colour of destination back to xlNone
    2+2=9 ... (My Arithmetic Is Mental)

Posting Permissions

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