宏未按应分割

时间:2018-12-26 21:44:37

标签: vba divide

我有一个有效的宏,但只有在除以19.00时才有效。如果要除以20.00或更高的数字,则仅除以10.00,仅此而已。要做的是将不超过12.00的任何数字划分为10个单元格,而超过12.00的任何数字都将多余的数字写入找到的对中的第一个数字。

此外,我的宏末尾引用了“ Range(“ G”&found).Value = pair”,但未写入任何内容。我真正需要的是删除它或使其灵活地写入特定的单元格,以便将来可以更改它,或者就像我说的将其删除。

如果有人可以看看我没看到的东西,肯定会感激的。

Sub DIVIDE()
Application.ScreenUpdating = False

Dim pair As Variant, accumulator As Variant
Dim findFifteen As Double
Dim remainder As Long, found As Long

found = 1

For Each pair In Range("B30, F30, J30")
If Right(pair, 2) = 15 Then
    If pair.Offset(0, 1) <= 12 Then
        findFifteen = pair.Offset(0, 2) / 10
        remainder = 0
    Else
        findFifteen = 1
        remainder = pair.Offset(0, 2) Mod 10
    End If

    For Each accumulator In Range("A36, D36, G36, J36, M36, A40, D40, G40, J40, M40")
        If accumulator.Offset(-1, 0) = Val(Left(pair, InStr(pair, "-") - 1) Then
            accumulator.Value = accumulator.Value + remainder
        End If
        accumulator.Value = accumulator.Value + findFifteen
    Next accumulator
Range("G" & found).Value = pair
found = found + 1
End If
Next pair

Application.ScreenUpdating = True
End Sub

EXCEL IMAGE

0 个答案:

没有答案