Thứ Năm, 31 tháng 3, 2016

VBA Excel - Tóm tắt Thuộc tính, đối tượng code ... thường sử dụng trong VBA

- WorksheetFunction

  Vd : 
Range(“A3”).Value = Application.WorksheetFunction.Average(Range(“A1:A2”)) Range(“A3”).Value = “=AVERAGE(A1:A2)”
- ScreenUpdating (Cập nhật màn hình)
Giả sử có đoạn code sau :
Dim i As Integer For i = 1 To 10000 Range(“A1”).Value = i Next i
Thay bằng :
Dim i As IntegerApplication.ScreenUpdating = False For i = 1 To 10000 Range(“A1”).Value = i
Next iApplication.ScreenUpdating = True
Kết quả code chạy nhanh hơn .
- DisplayAlerts (Hiển thị cảnh báo)
VD : Application.DisplayAlerts = False ActiveWorkbook.Close Application.DisplayAlerts = True
Không cho Excel hiển thị cảnh báo
- Calculation (Tính toán)
Vd :
Application.Calculation = xlCalculationManual Application.Calculation = xlCalculationAutomatic
- Range
VD :
Range(“B3”).Value = 2 Range(“A1:A4”).Value = 5 Range(“A1:A2,B3:C4”).Value = 10
- Cells
VD :
Cells(3, 2).Value = 2 Range(Cells(1, 1), Cells(4, 1)).Value = 5
- Khai báo một Range
Dim example As Range Set example = Range(“A1:C4”) example.Value = 8
- Workbooks.Add : Method Add của Workbooks tạo một workbook mới.


EmoticonEmoticon

:)
:(
hihi
:-)
:D
=D
:-d
;(
;-(
@-)
:o
:>)
(o)
:p
:-?
(p)
:-s
8-)
:-t
:-b
b-(
(y)
x-)
(h)