获取活动单元格的行索引或列索引(行号和列号)
Dim RowIndex As Integer
RowIndex = Target.Row
MsgBox "当前单元格所处的行是第:" & RowIndex&“行“
Dim ColIndex As Integer
ColIndex = Target.Column
MsgBox "当前单元格所处的列是第:" & ColIndex&“ 列“
-------------------------------------------------------------------------------
隐藏行
Sub HideRow()
Dim iRow As Long
MsgBox "隐藏当前单元格所在的行"
iRow = ActiveCell.Row
ActiveSheet.Rows(iRow).Hidden = True
MsgBox "取消隐藏"
ActiveSheet.Rows(iRow).Hidden = False
End Sub
--------------------------------------------------------------------------------
隐藏列
Sub HideColumn()
Dim iColumn As Long
MsgBox "隐藏当前单元格所在列"
iColumn = ActiveCell.Column
ActiveSheet.Columns(iColumn).Hidden = True
MsgBox "取消隐藏"
ActiveSheet.Columns(iColumn).Hidden = False
End Sub
--------------------------------------------------------------------------------
插入行
Sub InsertRow()
Dim rRow As Long
MsgBox "在当前单元格上方插入一行"
rRow = Selection.Row
ActiveSheet.Rows(rRow).Insert
End Sub
--------------------------------------------------------------------------------
插入列
Sub InsertColumn()
Dim cColumn As Long
MsgBox "在当前单元格所在行的左边插入一行"
cColumn = Selection.Column
ActiveSheet.Columns(cColumn).Insert
End Sub
--------------------------------------------------------------------------------
插入多行
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
--------------------------------------------------------------------------------
设置行高
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
--------------------------------------------------------------------------------
设置列宽
Sub SetColumnWidth()
MsgBox "将当前单元格所在列的列宽设置为30"
Dim cColumn As Long, iColumn As Long
cColumn = ActiveCell.Column
iColumn = ActiveSheet.Columns(cColumn).ColumnWidth
ActiveSheet.Columns(cColumn).ColumnWidth = 30
MsgBox "恢复至原来的列宽"
ActiveSheet.Columns(cColumn).ColumnWidth = iColumn
End Sub
--------------------------------------------------------------------------------
恢复行高列宽至标准值
Sub ReSetRowHeightAndColumnWidth()
MsgBox "将当前单元格所在的行高和列宽恢复为标准值"
Selection.UseStandardHeight = True
Selection.UseStandardWidth = True
End Sub