x = Range("b65536").End(xlUp).Row
当前表的行数
工作表行和列的操作
[示例01]隐藏行
Sub HideRow()
Dim iRow As Long
MsgBox "隐藏当前单元格所在的行"
iRow = ActiveCell.Row
ActiveSheet.Rows(iRow).Hidden = True
MsgBox "取消隐藏"
ActiveSheet.Rows(iRow).Hidden = False
End Sub
[示例02]隐藏列
Sub HideColumn()
Dim iColumn As Long
MsgBox "隐藏当前单元格所在列"
iColumn = ActiveCell.Column
ActiveSheet.Columns(iColumn).Hidden = True
MsgBox "取消隐藏"
ActiveSheet.Columns(iColumn).Hidden = False
文章内容来源于网络,由WPS之家(wps.qiangguoshuo.com)收集,希望能为您提供帮助。
End Sub[示例03]插入行
Sub InsertRow()
Dim rRow As Long
MsgBox "在当前单元格上方插入一行"
rRow = Selection.Row
ActiveSheet.Rows(rRow).Insert
End Sub
[示例04]插入列
Sub InsertColumn()
Dim cColumn As Long
MsgBox "在当前单元格所在行的左边插入一行"
cColumn = Selection.Column
ActiveSheet.Columns(cColumn).Insert
End Sub
[示例05]插入多行
Sub InsertManyRow()
MsgBox "在当前单元格所在行上方插入三行"
Dim rRow As Long, i As Long
For i = 1 To 3
rRow = Selection.Row
ActiveSheet.Rows(rRow).Insert
Next i
End Sub
[示例06]设置行高
Sub SetRowHeight()
MsgBox "将当前单元格所在的行高设置为25"
Dim rRow As Long, iRow As Long
rRow = ActiveCell.Row
iRow = ActiveSheet.Rows(rRow).RowHeight
ActiveSheet.Rows(rRow).RowHeight = 25
MsgBox "恢复到原来的行高"
ActiveSheet.Rows(rRow).RowHeight = iRow
End Sub
[示例07]设置列宽
Sub SetColumnWidth()
MsgBox "将当前单元格所在列的列宽设置为20"
Dim cColumn As Long, iColumn As Long
cColumn = ActiveCell.Column
iColumn = ActiveSheet.Columns(cColumn).ColumnWidth
ActiveSheet.Columns(cColumn).ColumnWidth = 20
MsgBox "恢复至原来的列宽"
ActiveSheet.Columns(cColumn).ColumnWidth = iColumn
End Sub
[示例08]恢复行高列宽至标准值
Sub ReSetRowHeightAndColumnWidth()
MsgBox "将当前单元格所在的行高和列宽恢复为标准值"
Selection.UseStandardHeight = True
Selection.UseStandardWidth = True
End Sub
转载声明:本站发布文章及版权归原作者所有,转载本站文章请注明文章来源!