0

我试图弄清楚如何做一个宏,它将数据从一张名为 Used Car Log 的工作表复制到另一张名为 Used Pending 的工作表上,但仅当在 Used Car Log 的 L 列中找到 x 时。如果在 L 列中找到 x,那么我需要将单元格 B 到 K(在该行上)中的所有数据复制到 Used Pending 到相应的列 B 到 K 中。我需要它找到下一个空白行以将其插入并且我需要它不重复任何数据。任何帮助,将不胜感激!我正在使用 Excel 2007。

4

3 回答 3

0

下面的代码将完全按照您的要求进行,但仅此而已。它将 L 列中的值设置为 xx(而不仅仅是 x)以不复制数据两次,并且假设 L 列中的 x-es 是有序的,这当然可能是一个错误的假设。

Sub CopyData()
Dim run As Boolean
Dim i As Integer
i = 1
run = True
While run
    If Worksheets("Used Car Log").Range("L" + CStr(i)).Value = "x" Then
        Worksheets("Used Pending").Range("B" + CStr(i) + ":K" + CStr(i)).Value = Worksheets("Used Car Log").Range("B" + CStr(i) + ":K" + CStr(i)).Value
        'Mark the value as copied by setting the value in column L as xx
        Worksheets("Used Car Log").Range("L" + CStr(i)).Value = "xx"
    ElseIf Worksheets("Used Car Log").Range("L" + CStr(i)).Value = "" Then
        run = False
    End If

    i = i + 1
Wend


End Sub
于 2013-09-03T19:15:13.953 回答
0

您是否尝试过使用 IF 功能?

例如,在Used Pending表中,您可以在单元格A1中使用如下公式:

=IF(UsedCarLog!L1="x",UsedCarLog!A1,"")

然后,删除Used Pending表中的所有空行。

于 2013-09-03T19:17:10.570 回答
0

尝试这个:

Sub FindAndMove()

Dim LastrowUP As Integer
Dim LastrowCarLog As Integer
Dim RowNumber As Integer

LastrowCarLog = Sheets("Used Car Log").Cells(Cells.Rows.Count, "B").End(xlUp).Row

For Each c In Sheets("Used Car Log").Range("L1:L" & LastrowCarLog)
 If c.text = "x" Then
 RowNumber = c.Row
 LastrowUP = Sheets("Used Pending").Cells(Cells.Rows.Count, "B").End(xlUp).Row
 Sheets("Used Car Log").Range("B" & RowNumber & ":" & "K" & RowNumber).Copy
 Sheets("Used Pending").Range("B" & LastrowUP + 1).PasteSpecial Paste:=xlPasteValues
 Application.CutCopyMode = False
 End If
Next c

Sheets("Used Pending").Range("B1:K" & LastrowUP + 1).RemoveDuplicates Columns:=Array(1, 2, 3, 4, 5, 6, 7 , 8, 9, 10), Header:=xlNo

End Sub

粘贴到 VB 编辑器中的新模块中。然后,在您的电子表格上创建一个按钮,右键单击,选择“分配宏”并选择 FindAndMove

于 2013-09-04T20:04:49.050 回答