|
楼主 |
发表于 2024-3-29 17:35
|
显示全部楼层
感谢帮忙,想请教一下,我根据另外的需求修改了一下代码,为啥我计算出来的结果不对的,就是结果工作表里的J5单元格的值错误,我所需正确的结果如L10单元格我用函数计算出来了,请问代码问题具体出在哪里了?
代码如下:
Sub ykcbf() '//2024.3.27
Application.ScreenUpdating = False
With Sheets("原始数据")
arr = .UsedRange
ReDim brr(1 To 10000, 1 To UBound(arr, 2))
m = 0
For i = 2 To UBound(arr)
If .Cells(i, 1).MergeCells Then
r = i: st = arr(i, 1)
m = m + 3
brr(m - 2, 1) = st & "A"
brr(m - 1, 1) = st & "B"
brr(m, 1) = arr(r, 1)
For j = 2 To UBound(arr, 2)
If j = 2 Then
brr(m - 2, j) = arr(r, j)
brr(m - 1, j) = arr(r + 1, j)
brr(m, j) = arr(r, j)
ElseIf j = 10 Then
brr(m - 2, j) = arr(r, j)
brr(m - 1, j) = arr(r + 1, j)
brr(m, j) = TimeValue(arr(r, 2)) + (arr(r, j) + arr(r + 1, j)) / 24
ElseIf j = 9 Then
brr(m - 2, j) = arr(r, j)
brr(m - 1, j) = arr(r + 1, j)
brr(m, j) = arr(r, j) + arr(r + 1, j)
Else
brr(m - 2, j) = arr(r, j)
brr(m - 1, j) = arr(r + 1, j)
brr(m, j) = arr(r, j) & "/" & arr(r + 1, j)
End If
Next
brr(m, UBound(arr, 2)) = arr(r, UBound(arr, 2)) + arr(r + 1, UBound(arr, 2))
i = i + 1
Else
m = m + 1
For j = 1 To UBound(arr, 2)
brr(m, j) = arr(i, j)
Next
End If
Next
End With
With Sheets("结果")
.[a2:k10000].Clear
.[a1].Resize(1, UBound(arr, 2)).Interior.Color = 49407
With .[a2].Resize(m, UBound(arr, 2))
.Value = brr
.Borders.LineStyle = 1
.HorizontalAlignment = xlCenter '//列居中
.VerticalAlignment = xlCenter
End With
End With
Application.ScreenUpdating = True
MsgBox "OK!"
End Sub
|
|