Excel VBA中选取单元格的方法汇总

2016-01-14 17:00 阅读 103 次 评论关闭

1、选取一个单元格:
Range("A1").select
Range("A" & 1).select
Cells(1).select
Cells(1, 1).select
Cells(1, "A").select
2、选取连续单元格:
Range("a1:b10").select
Range("a1", "b10").select
Range(Cells(1, 1), Cells(10, 2)).select
3、选取不连续单元格:
Range("a1,b2,c3").select
Union(Range("a1"), Range("b2"), Range("c3")).select
Union(Cells(1, 1), Cells(2, 2), Cells(3, 3)).select
4、选取行:
Range("1:1").select
Rows("1:1").select
Rows(1).select
Range("2:10").select
Rows("2:10").select
Range("1:1,3:5").select
5、选取列:
Range("A:A").select
Columns("A:A").select
Columns(1).select
Range("A:F").select
Columns("A:F").select
Range("A:B,D:F").select
6、选取所有单元格:
Cells.select
7、实现分块合并单元格
Range("b1:g1, h1:m1, n1:s1").MergeCells = True
**************************************************
取最后一行行号:i = Range("A65536").End(xlUp).Row
取最后一列列号:m = Range("dz1").End(xlToLeft).Column
**************************************************
Option Explicit
Dim i, j, m, iCol, iRow As Integer
Dim iCount, iSheet, iBook As Integer
’计算workbook中,每一个worksheet的cell为1的数目
Sub CheckNum()
iCount = 0
iBook = Application.Worksheets.Count
For i = 1 To iBook
Sheets(i).Activate
iRow = ActiveSheet.[c65535].End(xlUp).Row ’取最后一行
iCol = ActiveSheet.Range("dz2").End(xlToLeft).Column ’取最后一列
For j = 3 To iCol ’列循环
For m = 3 To iRow ’行循环
If ActiveSheet.Cells(j, m) = "1" Then
iCount = iCount + 1
End If
Next
Next
Next
MsgBox "方案数为: " & iCount
End Sub

版权声明:本文著作权归原作者所有,欢迎分享本文,谢谢支持!
转载请注明:Excel VBA中选取单元格的方法汇总 | 猎微网

评论已关闭!