1、定义一个Range对象。Dim rng As Range 2、引用Range对象 ,假设我们定义了一个工作表对象ws。Set rng = ws.Range("A1:B2")Set rng = ws.Range("C1")Set rng = ws.Range(ws.Cells(1, 1), ws.Cells(3, 3)).Set rng = ws.UsedRangeSet rng = ws.Range("A1").CurrentRegion 3、批注:Set r...
1、模块1,HighLight过程,高亮显示:Public LastRange As Range ' 用于存储上次突出显示的区域Public currCell As RangePublic Dic As ObjectPublic blnHighLight As BooleanSub HighLight() On Error Resume Next Dim dataRange As Range Dim currRange As Range Dim lastRow As Long Dim lastCol...
.Sheets(1).Range(Cells(1, 1), Cells(1, UBound(arrTem, 1) + 1)).MergeCells = True .Sheets(1).Range("A1") = Me.TxbTitle .Sheets(1).Range("A1").HorizontalAlignment = xlCenter Set rng = .Sheets(1).Range("A2").Resize(UBound(arrTem, 2) + 1, UBound(arrTem, 1) + 1) Else ...
RANG.COLUMN 组成其的第一个CELL的列数 举例 DIM RNG AS RANG SET RNG=SHEET1.RANG(SHEET1.CELLS(1,1),SHEET1,CELLS(2,3))这个列子中,定义了一个RANG对象的应用,使其应用到SHEET1的 (1,1)格和(2,3)格组成的一个大方框,这个方框区域成为RANG对象。
Set ws = Application.ActiveWorkbook.ActiveSheet Set allColumns = ws.Columns allColumns.Interior.Color = RGB(255, 0, 0) 上述代码将工作表的所有列的背景色置为红色 Columns也可以表示一个列, 需要加上参数, 列号(从1开始) Dim myColumn As range ...
Range("x41").ClearNotes 25.清除指定区域的分级显示。 Range("x41").ClearOutline 26.返回指定区域中第一块中的第一列的列号 MsgBox Range("x41").Column 27.返回一个 指定对象,该对象代表每列中所有与比较单元格内容不同的单元格。 Set a = Columns("x").ColumnDifferences(Range("x13")) ...
2 先说这一种,分别设置列宽行高的数值(直接操作的做法是在列头或者行头右键来修改列宽或行高的值),而vba的代码如下(附上释义):Sub 设置列宽行高()With ActiveWindow.RangeSelection '对活动工资表被选中的单元格赋属性.ColumnWidth = 12 '列宽以字符为单位.RowHeight = 72'行高以磅为单位...
Sub 循环单元格() Dim ws As Worksheet Dim rng As Range Dim cell As Range Set ws = ThisWorkbook.Sheets("表3") Set rng = ws.Range(Cells(1, 1), Cells(10, 10)) For Each cell In rng If cell.Row = cell.Column Then cell.Interior.Color = vbRed Else ce...
=OFFSET($A$1,COLUMN(A1)-1,ROW(A1)-1)4、VBA代码法:(1)数组法 Sub transfrom() Dim arr(), arrTem(), iRow As Integer, iCol As Integer Dim ws As Worksheet Set ws = Sheets("Sheet1") ws.Activate With ws iRow = .UsedRange.Rows.Count iCol = .UsedRange.Column...