Public WorkRange As Range
Dim NumAreas As Integer, i As Integer
Sub Xoa_DL()
If MsgBox(" Ban chac chan muon xoa du lieu chu?" & vbCrLf & vbCrLf _
& "Ban chi co the phuc hoi mot lan. Ban co muon tiep tuc?", 64 + 4, "Xac nhan thong tin") <> 6 Then Exit Sub
Sheets("cdpstk").Range("D10:G12,D14:G16,D18:G19,D21:G22,D24:G25,D28:G29,D31:G32,D34:G35,D37:G44,D46:G50,D52:G57,D59:G65,D67:G73,D75:G82,D84:G87,D89:G96,D98:G99,D102:G111,D113:G117,D119:G129,D131:G137,D139:G143,D145:G148,D150:G156,D158:G159,D161:G165,D167:G175,D177:G184,D186:G192,D194:G203,D205:G207,D210:G215").Select
On Error Resume Next
Set WorkRange = Selection
Sht.Range(WorkRange.Address).Clear
If TypeName(Selection) <> "Range" Then
MsgBox "Xin hay chon vung ban muon xoa.", vbExclamation, EXname: Exit Sub
End If
NumAreas = WorkRange.Areas.Count
For i = 1 To NumAreas
WorkRange.Areas(i).Copy Sht.Range(WorkRange.Areas(i).Address)
Next
WorkRange.ClearContents
Application.OnUndo "Undo ClearContents", "UndoClearContents"
End Sub
Public Sub UndoClearContents()
On Error GoTo ErrHandler
Application.ScreenUpdating = False
On Error Resume Next
For i = 1 To NumAreas
Sht.Range(WorkRange.Areas(i).Address).Copy WorkRange.Areas(i)
Next
Application.ScreenUpdating = True
On Error GoTo 0
MsgBox "Da khoi phuc thanh cong!", 64, "Ok"
Exit Sub
ErrHandler:
Application.ScreenUpdating = True
MsgBox "Khong the khoi phuc lai!", 48, "Error"
On Error GoTo 0
End Sub