【问题标题】:Beginner problems with Excel Macro VBAExcel宏VBA的初学者问题
【发布时间】:2017-08-24 19:06:16
【问题描述】:

我有一个关于 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

谁能帮帮我?

【问题讨论】:

  • 您说“帮助”,但没有您自己的任何代码,看起来您只是希望有人为您编写它......

标签: excel vba


【解决方案1】:

我觉得我已经找到了(还没有真正测试过)

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-01-04
    • 2020-11-23
    • 2015-03-16
    • 2012-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多