2. 高亮选中单元格所在的行和列。 Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Target.Cells.Count > 1 Then Exit Sub Application.ScreenUpdating = False ' Clear the color of all the cells Cells.Interior.ColorIndex = 0 With Target ' Highlight the entire row and column that ...
、选取一个单元格: 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"...
lastCol = Range("a1").End(xlToRight).Column lastRow = Cells(65536, lastCol).End(xlUp).Row Range("a1", sht_temp.Cells(lastRow, lastCol)).Select 但当要选择下面这样的表格时,以上脚本就不行了,因为无法识别图表内左上角的空白区域。 可以使用 Range(Range("A" & 1), Range("a1").SpecialCel...
1. Columns对象: 使用Columns对象,可以通过指定列号来选中指定列。下面给出一段VBA代码可以帮助你实现这一目标: Sub SelectColumnByNumber() Dim columnNumber As Integer columnNumber = 3 ' 将这里的3替换为您想要选择的列号 Columns(columnNumber).Select End Sub 在上面的代码中,columnNumber变量是需要替换的列...
Rows(ActiveSheet.usedrange.Row).Select '选择已使用区域第一行,包括隐藏区域 Columns(ActiveSheet.usedrange.Column).Select '选择已使用区域第一列,包括隐藏区域 Cells(ActiveSheet.usedrange.Row, ActiveSheet.usedrange.Column).Select '已使用区域第一个单元格 包括隐藏区域 ActiveSheet.usedrange.SpecialCells(11).Select...
在《Excel VBA解读(8):看看Excel的那些常用对象(续2)》中,我们介绍过Rows属性和Columns属性,在VBA中使用这两个属性可以表示整行或整列组成的区域,也可以表示单元格区域中的行或列。举一些例子来说明。 Rows代表工作表中的所有行,...
Columns(1).select 选择第一列 Columns.Select 选择所有列 上面说到了怎么选择单元格,行,列,区域,都是直接指定的,有明确目标的,但我们学习VBA就是要实现智能化,自动化,这样的我们就要用到变量来代替,那么怎么用变量来选择区域呢? 上面的例子有提到,使用range("A1")这样的方法来选择是要加英文双引号的,代表是...
代码语言:vba 复制 Sub SelectAllCellsInColumn() Dim LastRow As Long LastRow = Cells(Rows.Count, "A").End(xlUp).Row Range("A1:A" & LastRow).Select End Sub 这段代码首先通过Cells(Rows.Count, "A").End(xlUp).Row获取列"A"中最后一个非空单元格所在的行数,然后使用Range("A1:A" ...
Rows(“9:9”).Select Selection.Rows.AutoFit Columns(“B:D”).Select Selection.Columns.AutoFit End Sub ‘设置当前单元格的列宽 Sub SetColumnWidth() MsgBox “将当前单元格所在列的列宽设置为20” Dim cColumn As Long,iColumn As Long cColumn=ActiveCell.Column ...
Range("A1").Select To select a set of contiguous cells you will write: Range("A1:A5").Select To select a set of non contiguous cells you will write: Range("A1,A5,B4").Select Columns, Rows, Select, EntireRow, EntireColumn To select a column you will write: ...