求VBA大神解析一套简单的代码

小白学习遇到的简单问题,希望大神解析一下,已举例

'strAddr(举例解析:单元格地址)
Sub getDataByAddress(strAddr As String)
Dim sht As Worksheet
Dim n As Integer: n = 3

With ActiveSheet
.Range("2:1000").ClearContents
.Range("A3:B3") = Array("表名", "结果")
End With

For Each sht In ThisWorkbook.Worksheets

If sht.Name <> ActiveSheet.Name Then
n = n + 1
Cells(n, 1) = sht.Name
Cells(n, 2) = sht.Range(strAddr).Value
End If
Next
End Sub

'change
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address(0, 0) = "B1" Then
getDataByAddress Range(Target.Address(0, 0)).Value
End If
End Sub

strAddr(举例解析:单元格地址)
Sub getDataByAddress(strAddr As String)
声明sht为工作表对象。
Dim sht As Worksheet
声明n为整数,并且赋值为三。
Dim n As Integer: n = 3
对于激活的工作表。
With ActiveSheet
清除第2到1000行内容。
.Range("2:1000").ClearContents
A3等于表明。
B3等于结果。
.Range("A3:B3") = Array("表名", "结果")
End With

遍历所有工作表。
For Each sht In ThisWorkbook.Worksheets
排除当前激活的工作表。
If sht.Name <> ActiveSheet.Name Then
n = n + 1
Cells(n, 1) = sht.Name 工作表名称
Cells(n, 2) = sht.Range(strAddr).Value 目标单元格的地址
End If
Next
End Sub

'change
工作表变动事件。
Private Sub Worksheet_Change(ByVal Target As Range)
如果目标地址不为b1
If Target.Address(0, 0) = "B1" Then
执行子程序getDataByAddress Range
getDataByAddress Range(Target.Address(0, 0)).Value
End If
End Sub
温馨提示:答案为网友推荐,仅供参考