|
楼主 |
发表于 2024-1-21 20:00
来自手机
|
显示全部楼层
下面是在手机写的代码,还没经过验证。代码的意思: 在各个工作表里找跟活动工作表里相同的项(最近时间的),并根据相同的项对应的项,修改工作表里内容。最近时间是从右往左开始工作表的,找到了就退出循环。
Private Sub Worksheet_Change(ByVal Target As Range)
Dim arr, arr1, arr2
Dim z%, x%, y%, k%, j%
Application.ScreenUpdating = False
Sheets(Sheets.Count).Activate
arr = Range("A3:B" & _
Range("A3").End(xlDown).Row)
For z = 1 To UBound(arr)
For x = Sheets.Count - 1 to 1 Step -1
arr1 = Sheets(x).Range("C3:I" & _
Range("C6000").End(xlUp).Row)
For y = 1 To UBound(arr1)
If arr1(y, 1) = arr(z, 1) Then
k = k + 1
arr2(k) = arr1(y, 3)
End If
Next
If k > 0 Then
For j = 1 to UBound(arr1)
If arr1(j, 1) = arr(z, 1) And _
arr1(j, 3) = Max(arr2) Then
arr1(j, 4) = "文本1"
arr1(j, 6) = "文本2"
Exit For
End If
Next
Sheets(x).Range("C3:I" & _
Range("C6000").End(xlUp).Row) = arr1
Exit For
End If
Next
If k = 0 Then
arr(z, 2) = "未找到"
Next
Range("A3:B" & _
Range("A3").End(xlDown).Row) = arr
Application.ScreenUpdating = True
End Sub
|
|