首页 > 解决方案 > 宏没有按应有的方式划分

问题描述

我有一个可以工作的宏,但只有在除以 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

优秀图片

标签: vbadivide

解决方案


推荐阅读