Fork me on GitHub

[VBA] 设置行高和列宽,以及全选单元格

一、用VBA设置行高和列宽

  1、将选定区域内各单元格的行高和列宽设置为指定的数值:  

Sub SetSpecified()
    With ActiveWindow.RangeSelection
      .ColumnWidth = 2
      .RowHeight = 10
    End With
End Sub

  2、将选定区域内各单元格的行高和列宽调整为最合适的值:  

Sub SetAutoFit()
    With ActiveWindow.RangeSelection
      .Columns.AutoFit
      .Rows.AutoFit
    End With
End Sub

  3、将活动工作表中的所有单元格的行高和列宽恢复为默认值:  

Sub SetDefault()
    With ActiveSheet
      .Columns.ColumnWidth = .StandardWidth
      .Rows.RowHeight = .StandardHeight
    End With
End Sub

 二、用VBA全选单元格

  1、选择所有单元格(Cells是所有单元格的集合)

Sub SelectAllCells()
    Cells.Select
End Sub

  2、选择所有行(Rows是所有行的集合)

Sub SelectAllRows()
    Rows.Select
End Sub

  3、选择所有列(Columns是所有列的集合)

Sub SelectAllColumns()
    Columns.Select
End Sub

posted on 2011-10-11 22:31  RussellLuo  阅读(9545)  评论(0编辑  收藏  举报

导航