|
楼主 |
发表于 2024-1-7 11:02
|
显示全部楼层
感谢chxw68老师!
Sub 查找I3单元格的月份列二()
Dim myr%, rng As Range, fhzm$, zmz%, szz$
Dim arr, br1(), br2(), i%, j%, n%
Dim x%, sumx1&, sumx2& '变量存放结果
With Sheets("完成情况明细表")
If Range("i3").Value = "" Then Exit Sub
myr = Range("b65536").End(xlUp).row
Set rng = Range("aa6:ax6").Find(Range("i3"), LookAt:=xlWhole) '完全匹配
fhzm = Split(rng.Address(1, 1), "$")(1) '返回列字母
zmz = Range("a1:" & fhzm & "1").Cells.Count + 1 '字母转列数
szz = Replace(Cells(1, zmz).Address(False, False), "1", "") '列数转字母
arr = Range("aa8:" & szz & myr)
For i = LBound(arr) To UBound(arr)
ReDim br1(1 To UBound(arr, 2) / 2)
ReDim br2(1 To UBound(arr, 2) / 2)
n = 0
For j = LBound(arr, 2) To UBound(arr, 2) Step 2
n = n + 1
br1(n) = arr(i, j)
br2(n) = arr(i, j + 1)
Next j
sumx1 = 0 '初始化结果为0
For x = 1 To UBound(br1)
sumx1 = sumx1 + br1(x) '将当前元素加到结果上
Next
sumx2 = 0
For x = 1 To UBound(br2)
sumx2 = sumx2 + br2(x) '将当前元素加到结果上
Next
Range("y" & 7 + i) = sumx1
Range("z" & 7 + i) = sumx2
Next i
End With
End Sub |
|