在Excel中重新排列字符串列表

时间:2019-02-18 15:26:22

标签: excel

enter image description here

我使用下面的代码,出了点问题。我的任务是根据一些规则重新排列E列中的字符串。即,如果B1为21,则下一个字符串必须是A等于1或3的字符串。看起来很琐碎,但是代码无法正常工作。

Sub qwer()
For i = 1 To 80
    k = 2
    Z = Cells(i, "B").Value
    If Z = 22 Then
        Do Until Cells(k, "A").Value = 2 Or 4 'do until the condition is not met
        k = k + 1
        Loop
        Cells(k, "F").Value = Cells(k, "E").Value
        Cells(k, "A").Value = ""
    End If

    If Z = 21 Then
        Do Until Cells(k, "A").Value = 1 Or 3
        k = k + 1
        Loop
        Cells(k, "F").Value = Cells(k, "E").Value
        Cells(k, "A").Value = ""
    End If

    If Z = 23 Then
        Do Until Cells(k, "A").Value = 3 Or 5
        k = k + 1
        Loop
        Cells(k, "F").Value = Cells(k, "E").Value
        Cells(k, "A").Value = ""
    End If

    If Z = 24 Then
        Do Until Cells(k, "A").Value = 4 Or 2
        k = k + 1
        Loop
        Cells(k, "F").Value = Cells(k, "E").Value
        Cells(k, "A").Value = ""
    End If

    If Z = 25 Then
        Do Until Cells(k, "A").Value = 5 Or 1
        k = k + 1
        Loop
        Cells(k, "F").Value = Cells(k, "E").Value
        Cells(k, "A").Value = ""
    End If
Next
End Sub

0 个答案:

没有答案