[Excel二次开发]行(Rows)、列(Columns)和单元格(Range)的选择
试试调整注释的语句你就明白了!
Sub Tset() With Sheets("DEMO") 'Rows(1).Select 'Rows.Select 'Columns (1).Select 'Columns("F").Select 'Columns (6).Select 'Columns.Select 'Range("F7:F1048576").Select End With With Sheets("DEMO") Dim myUnion As Range Set myUnion = Union(Rows(1), Rows(3), Rows(5), Columns(1), Columns(3), Columns(5), Range("G13:G20"), Range("H27")) myUnion.Select End With End Sub
特别的,Columns指令在遇到需要选中的列包含已合并单元格的行时,将不再选中该列,而是选中包含合并的行在内的所有的列!
Sub Tset() With Sheets("DEMO") 'Rows(1).Select 'Rows.Select 'Columns (1).Select 'Columns("F").Select Columns(6).Select 'Columns.Select 'Range("F7:F1048576").Select End With 'With Sheets("DEMO") ' Dim myUnion As Range ' Set myUnion = Union(Rows(1), Rows(3), Rows(5), Columns(1), Columns(3), Columns(5), Range("G13:G20"), Range("H27")) ' myUnion.Select 'End With End Sub