Application.Workbooks("Book1.xlsx").Worksheets("Sheet1").Range("A1")
Range("A1").ClearContents
循环的方式
For Each cmt in ActiveSheet.Comments
MsgBox cmt.Text
Next cmt
For Each Sht In ActiveWorkbook.Sheets
MsgBox Sht.Name
Next Sht
For i = 1 To 100
Total = Total + i
Next i
MaxVal = Application.WorksheetFunction.Max(Range("A:A"))
IF Application.WorksheetFunction.IsNumber(item) THEN
单元格之间的拷贝
Range("A1").Copy Range("c1")
范围拷贝
Range("A1:B5").Copy Range("c1")
移动一个范围
Range(A1:A5).cut Range(“C1”)
由一个点获取一个区域(Ctrl+Shift+*)
set rng = Range(“A1”).CurrentRegion
查找第一个空行的前一行 (xlUp, xlToLeft, and xlToRight)
endRow = Range(“A1”).End(xlDown).Row
取得最后一个非空行
LastRow = Cells(Rows.count,1).end(xlUp).Row
从画面传入值给VBA的运用
Range(“A1”).value = InputBox(“Enter the value”)
Sheet的所有行数
Rows.count
通过Cells来定位单元格,并且设定值
Cells(row, col) = value
Set FormulaCells = Selection.SpecialCells(xlFormulas, xlNumbers)
Set ConstantCells = Selection.SpecialCells(xlConstants, xlNumbers)
删除空白行
Sub DeleteEmptyRows() Dim LastRow As Long Dim r As Long Dim Counter As Long Application.ScreenUpdating = False LastRow = ActiveSheet.UsedRange.Rows.Count + _ ActiveSheet.UsedRange.Rows(1).Row - 1 For r = LastRow To 1 Step -1 If Application.WorksheetFunction.CountA(Rows(r)) = 0 Then Rows(r).Delete Counter = Counter + 1 End If Next r Application.ScreenUpdating = True MsgBox Counter & " empty rows were deleted." End Sub