VBA如何获取单元格焦点移动前的单元格的行号和列号? 20
2个回答
展开全部
在模块中定义2个全局变量iRow,iCol
然后在thisworkbook中的Workbook_Open()事件中,取得工作薄一开始时的初始单元格行号和列号,作为初始行号和列号:
Private Sub Workbook_Open()
iRow = ActiveCell.Row
iCol = ActiveCell.Column
End Sub
再然后在sheet1的Worksheet_SelectionChange(ByVal Target As Range)事件中,加下如下代码:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim reRow As Integer, reCol As Integer
reRow = Target.Row
reCol = Target.Column
Target.Value = "移动前单元格行号是:" & iRow & vbCrLf & "移动前单元格列号是:" & iCol
Cells(iRow, iCol) = ""
iRow = reRow
iCol = reCol
End Sub
然后在thisworkbook中的Workbook_Open()事件中,取得工作薄一开始时的初始单元格行号和列号,作为初始行号和列号:
Private Sub Workbook_Open()
iRow = ActiveCell.Row
iCol = ActiveCell.Column
End Sub
再然后在sheet1的Worksheet_SelectionChange(ByVal Target As Range)事件中,加下如下代码:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim reRow As Integer, reCol As Integer
reRow = Target.Row
reCol = Target.Column
Target.Value = "移动前单元格行号是:" & iRow & vbCrLf & "移动前单元格列号是:" & iCol
Cells(iRow, iCol) = ""
iRow = reRow
iCol = reCol
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询