Excel宏VBA

时间:2016-01-21 14:32:54

标签: excel vba

我对Excel有疑问。

我有一张包含一些列的表格,例如:

A         B         C
------------------------   
1   test    1
2   test    5
3   test    5
4   test    2
4   test    6
5   test    7
6   test    8
7   test    2
8   test    3
9   test    3
9   test    1
9   test    4
10  test    5

我想要一个执行以下操作的宏。它检查C.如果C的值小于3,则将该行和所有后续行中的相同值复制到A中,直到A更改为新工作表,然后再次检查C,依此类推。

这里的输出应该是:

带有

的新表格
a b c

4 test 2
4 test 6
7 test 2
9 test 1
9 test 4

有人可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

想想我发现它(还没有真正测试过它)

Sub CustomcCopy()
Dim controleValue As Double
controleValue = 3
Dim AValue As String
Dim lastline As Integer, tocopy As Integer

lastline = Range("F65536").End(xlUp).Row
j = 1

For i = 1 To lastline
    For Each c In Range("L" & i)
        If (c < controleValue And c > 0) Then
            tocopy = 1
        End If
    Next c
    If tocopy = 1 Then
    AValue = Cells(i, "A").Value

    Do While Cells(i, "A").Value = AValue

        Rows(i).Copy Destination:=Sheets(2).Rows(j)
        j = j + 1
        i = i + 1
    Loop

    End If
tocopy = 0
Next i

End Sub
相关问题