XD360 KÍNH CHÚC CHO MỌI NHÀ VẠN SỰ AN LÀNH!

Phần mềm ôn thi sát hạch chứng chỉ hành nghề xây dựng

 Quên mật khẩu
 Đăng ký mới
Anh Trần HòeBùi Quốc Hưng
Xem: 6900|Trả lời: 24
In Chủ đề trước Tiếp theo
Thu gọn cột thông tin

Mẹo thông minh giúp sửa code Macro excel tiết kiệm thời gian

[Lấy địa chỉ]
1#
laocong Đăng lúc 3/8/2014 22:40 | Xem tất
Nhưng do macro không cho phép undo.

Why NOT ????
Who 's  telll you that ?????

J-walk có cho free thời xưa

The Undo example


[Visual Basic] 纯文本查看 复制代码
'Custom data type for undoing
    Type SaveRange
        Val As Variant
        Addr As String
    End Type
    
'   Stores info about current selection
    Public OldWorkbook As Workbook
    Public OldSheet As Worksheet
    Public OldSelection() As SaveRange


Sub ZeroRange()
'   Inserts zero into all selected cells

'   Abort if a range isn't selected
    If TypeName(Selection) <> "Range" Then Exit Sub
    
'   The next block of statements
'   Save the current values for undoing
    ReDim OldSelection(Selection.Count)
    Set OldWorkbook = ActiveWorkbook
    Set OldSheet = ActiveSheet
    i = 0
    For Each cell In Selection
        i = i + 1
        OldSelection(i).Addr = cell.Address
        OldSelection(i).Val = cell.Formula
    Next cell
            
'   Insert 0 into current selection
    Application.ScreenUpdating = False
    Selection.Value = 0
    
'   Specify the Undo Sub
    Application.OnUndo "Undo the ZeroRange macro", "UndoZero"
End Sub


Sub UndoZero()
'   Undoes the effect of the ZeroRange sub
    
'   Tell user if a problem occurs
    On Error GoTo Problem

    Application.ScreenUpdating = False
    
'   Make sure the correct workbook and sheet are active
    OldWorkbook.Activate
    OldSheet.Activate
    
'   Restore the saved information
    For i = 1 To UBound(OldSelection)
        Range(OldSelection(i).Addr).Formula = OldSelection(i).Val
    Next i
    Exit Sub

'   Error handler
Problem:
    MsgBox "Can't undo"
End Sub


Đánh giá

Chia sẻ hay! Thanks bạn nhé!: 5.0
Chia sẻ hay! Thanks bạn nhé!: 5
Bài viết xin dùng tiếng Việt nhé!. Bài viết hay!  Đăng lúc 4/8/2014 14:18

www.xaydung360.vn XÂY TÂM, DỰNG TẦM CHUYÊN NGHIỆP

Phiên bản Mobile|Phần mềm ôn thi sát hạch chứng chỉ hành nghề xây dựng  

Phần mềm dự toán xây dựng excel | Hướng dẫn lập dự toán xây dựng | Phần mềm tư vấn giám sát | Phần mềm quản lý chất lượng xây dựng |

Phần mềm ôn thi sát hạch chứng chỉ hành nghề xây dựng

Phần mềm ôn thi sát hạch chứng chỉ hành nghề Kiến Trúc sư

Phần mềm ôn thi sát hạch chứng chỉ hành nghề Đấu thầu

GMT+7, 2/5/2024 12:01 , Processed in 0.143499 second(s), 28 queries .

Powered by Discuz! X3.2

© 2001-2013 Kiso Comsenz Inc.