逐句讲解下面宏的含义

问题描述:

逐句讲解下面宏的含义
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim rr As Integer
Dim rng As Range
For rr = 1 To 39
Set rng = Intersect(Target,Range("G" & rr))
If Not rng Is Nothing Then
Range("H1") = Range("G" & rr).Value
End If
Next rr
End Sub

'私有的事件过程,当工作表被选择的部分发生改变时被调用,Target中包含了改变后的区域
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim rr As Integer '声明整形变量rr
Dim rng As Range '声明range对象rng
For rr = 1 To 39 '从G1到G39单元格
Set rng = Intersect(Target,Range("G" & rr)) 'rr设定为变化后的选定区域与G1到G39的交集
If Not rng Is Nothing Then '若交集为空,就是说如果G1到G39中没有包含被选定的部分
Range("H1") = Range("G" & rr).Value '则H1单元格设为该交集最下面的格子的数值
End If
Next rr
End Sub