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")).sele...
例二、用Sheet1.Range("a1:a10") 定位 '方法:实际上就是对对象的操作,它是一种动作,一种行为。 Sub 选择方法() Range("a1:a10").Select '注:如果单元格区域前没有写工作表名,则默认为活动工作表 End Sub Sub 复制方法() Sheet1.Range("a1:a10") = 1 '将1写入表一的a1:a10区域 Sheet1.Range...
1 关闭除VBA中的必需品之外的所有东西2 通过系统设置禁用Office动画3 删除不必要的Select方法4 使用With语句读取对象属性5 使用 ranges 和 arrays6 使用 .Value2 而不是 .Text 或 .Value7 绕过剪贴板(复制和粘贴)8 使用 Option Explicit 捕捉未声明的变量 1 关闭除VBA中的必需品之外的所有东西 加速VBA 代码时...
表达式可以是Worksheet对象或者Range对象,在第一种方法中,Cell是必选参数,而且必须使用宏语言的A1样式引用,如: Worksheets("Sheet1").Range("A1").Select Worksheets("Sheet1").Range("A1:F100") 第二种方法使用中的Cell1,Cell2参数为区域左上角和右下角的单元格,如: Worksheets("Sheet1").Range(Cells(1,...
2)Set myrng = Range("A1").CurrentRegion 这句代码将以A1为基准,设置了当前的单元格区域,并赋给myrng 变量。3)myMAX = WorksheetFunction.Max(myrng)这句代码利用了一个工作表函数求出当前区域的最大值。WorksheetFunction表示利用的函数(Max)是工作表函数。4) For Each mycell In myrng 上述代码在...
Select Case This Case 0, "sheet","worksheet": If Target Is Nothing Then Set Target =Application.ThisCell vResult = Target.Parent.Name Case 1, "book","workbook": If Target Is Nothing Then Set Target =Application.ThisCell vResult = Target.Parent.Parent.Name ...
Range("1:1").Select Select an entire column Range("A:A").Select Select the last cell of a column of contiguous data Range("A1").End(xlDown).Select When this code is used with the following example table, cell A3 will be selected. ...
Select Case 表达式 Case 条件1 处理1 Case 条件2 处理2 …… Case Else 其他处理 End Select 语法中,在Select Case后面放置表达式部分,并按此表达式进行分别处理。如果与所有条件都不符合,就会执行Case Else中的处理,而且,Case的分支无数量限制。 2、举个例子 例1: “A1:A10单元格”区域的值如果为70以上就...
Select Case This Case 0, "sheet","worksheet": If Target Is Nothing Then Set Target =Application.ThisCell vResult = Target.Parent.Name Case 1, "book","workbook": If Target Is Nothing Then Set Target =Application.ThisCell vResult = Target.P...
Step 3:In the VBA editor, click "Insert" from the menu and then select "Module" to insert a new module. Step 4:In the module, enter the following VBA code: Sub SetCellColors() ' Set the fill color of cell A1 to yellow (ColorIndex 6) ...