Excel VBA函数

来源:http://www.gisall.com/?uid-153242-action-viewspace-itemid-5903

Rows.Count    显示所有行的数目
Column.Count    显示所有列的数目
Cells(Rows.Count, 1).End(xlUp).Row    显示第一列从下面数第一个有值的单元格的行号
Cells(1, Columns.Count).End(xlToLeft).Column    显示第一行从右面数第一个有值的单元格的列号
Cells(1, 1).BorderAround xlContinuous, xlThin    给A1单元格加入外边框
Range("A1:B4").Borders.LineStyle. = xlContinuous    给这个区域加入边框
Cells(1, 1).MergeArea.Count    计算合并单元格的总单元格数
Cells(1, 1).MergeArea.Rows.Count    计算合并单元格的行数
Cells(1, 1).MergeArea.Columns.Count    计算合并单元格的列数
Cells(1, 1).MergeCells    返回Boolean,True和False
Rnd()函数    返回小于1,大于等于0的一个随机数
Cells(1, 1).Interior.ColorIndex = Int(56 * Rnd() + 1)    给单元格内部赋个随机的颜色
Cells(1, 1).EntireColumn    包含此单元格的列
Cells(1, 1).EntireRow    包含此单元格的行
Cells.Interior.ColorIndex = xlColorIndexNone    所有单元格五色
Set rng = Application.Union(Target.EntireRow, Target.EntireColumn)    设置合并区域,注意Union方法是在Application下面的
Set rng = Sheet1.UsedRange.SpecialCells(xlCellTypeFormulas)    找出具有公式的单元格区域
Sheet1.Range("A:A").ClearContents    清除第一列的所有内容
Sheet1.Range("A:A").Clear    清楚第一列的所有东西,包括值、格式等
For Each rng In Sheet2.Range("A1:A40")    遍历区域内的每个单元格

Range("A:A").Replace "区", "市"    替换
Range("A:A").Replace What:="区", Replacement:="市"    替换

Sheet1.Range("A1:G7").Copy Sheet2.Range("A1")    复制区域,高宽变化
Sheet1.Range("A1:G7").Copy    复制区域
Sheet3.Range("A1").PasteSpecial xlPasteColumnWidth    黏贴相同宽度,相同高度要自己设置

Range("B1:B20").Validation.Add Type:=xlValidateList, Formula1:="A,B,C,D,E,F,G"    数据有效性

你可能感兴趣的:(Excel)