Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VBA根据排名分配值_Vba_Excel_Distribution_Ranking - Fatal编程技术网

VBA根据排名分配值

VBA根据排名分配值,vba,excel,distribution,ranking,Vba,Excel,Distribution,Ranking,尝试完成一次每3行处理一次的VBA。 使用秩列的顺序,将值相应地分配到下三行,每个单元格不超过最大值62,并对最高秩进行优先级排序 样本数据: max_value = 62 For irow = 2 To 80 Step 3 set_value = .Cells(irow, 2).Value 'if value less than max, then assign value to highest rank If set_value < max_value Th

尝试完成一次每3行处理一次的VBA。 使用秩列的顺序,将值相应地分配到下三行,每个单元格不超过最大值62,并对最高秩进行优先级排序

样本数据:

max_value = 62
For irow = 2 To 80 Step 3

    set_value = .Cells(irow, 2).Value

    'if value less than max, then assign value to highest rank
    If set_value < max_value Then
        toprank_value = .Range(.Cells(irow, 1), .Cells(irow + 3, 1)).Find(what:="1", LookIn:=xlValues).Address

        'assign value to rank of 1
        toprank_value.Offset(0, 2).Value = set_value

        GoTo NextIteration

    'if not, distribute values across next 3 rows based on rank not going over max of 62
    Else

        'NEED HELP FOR CODE HERE
        'NEED HELP FOR CODE HERE

    End If

NextIteration:
    Next

以下是我目前掌握的信息:

max_value = 62
For irow = 2 To 80 Step 3

    set_value = .Cells(irow, 2).Value

    'if value less than max, then assign value to highest rank
    If set_value < max_value Then
        toprank_value = .Range(.Cells(irow, 1), .Cells(irow + 3, 1)).Find(what:="1", LookIn:=xlValues).Address

        'assign value to rank of 1
        toprank_value.Offset(0, 2).Value = set_value

        GoTo NextIteration

    'if not, distribute values across next 3 rows based on rank not going over max of 62
    Else

        'NEED HELP FOR CODE HERE
        'NEED HELP FOR CODE HERE

    End If

NextIteration:
    Next
max_值=62
对于irow=2到80,步骤3
设置_值=.Cells(irow,2).value
'如果值小于最大值,则将值分配给最高秩
如果设置值<最大值,则
toprank_值=.Range(.Cells(irow,1),.Cells(irow+3,1)).Find(what:=“1”,LookIn:=xlValues)。地址
'将值赋给1的秩
toprank_值。偏移量(0,2)。值=设置_值
后藤下滴度
'如果不是,则根据排名不超过62的最大值,在接下来的3行中分配值
其他的
'此处需要代码帮助吗
'此处需要代码帮助吗
如果结束
下一次滴定:
下一个

感谢您对正确方向的任何提示或需要澄清的情况。

假设您要分配的值始终位于3行中的第一行。 这很难看,但似乎有效

Sub distrib()

Set R1 = ActiveSheet.UsedRange 'Edit range if other data in sheet
T1 = R1

M = 62

For i = 2 To UBound(T1)
    If T1(i, 2) > 0 Then
        V = T1(i, 2)
        If V <= M Then
            For j = i To i + 2
                If T1(j, 1) = 1 Then
                    T1(j, 3) = V
                Else
                    T1(j, 3) = 0
                End If
            Next j
        Else
            A = M
            V = V - M
            If V > M Then
                B = M
                V = V - M
                If V > M Then
                    C = M
                Else
                    C = V
                End If
            Else
                B = V
                C = 0
            End If
            For j = i To i + 2
                Select Case T1(j, 1)
                    Case Is = 1
                        T1(j, 3) = A
                    Case Is = 2
                        T1(j, 3) = B
                    Case Is = 3
                        T1(j, 3) = C
                End Select
            Next j
        End If
    End If
Next i

For i = 2 To UBound(T1)
    Cells(i, 3) = T1(i, 3)
Next i

End Sub
子发行版()
如果工作表中有其他数据,则设置R1=ActiveSheet.UsedRange“编辑范围”
T1=R1
M=62
对于i=2至UBound(T1)
如果T1(i,2)>0,那么
V=T1(i,2)
如果V M那么
B=M
V=V-M
如果V>M那么
C=M
其他的
C=V
如果结束
其他的
B=V
C=0
如果结束
对于j=i到i+2
选择案例T1(j,1)
情况是=1
T1(j,3)=A
情况是=2
T1(j,3)=B
情况是=3
T1(j,3)=C
结束选择
下一个j
如果结束
如果结束
接下来我
对于i=2至UBound(T1)
单元(i,3)=T1(i,3)
接下来我
端接头

非常感谢语法对调整非常有帮助