Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/26.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
Excel 根据条件从其他图纸复制行_Excel_Vba - Fatal编程技术网

Excel 根据条件从其他图纸复制行

Excel 根据条件从其他图纸复制行,excel,vba,Excel,Vba,目前,我有一个某种类型的跟踪表单,当表单中的字段被填充时,它会被发送到合并的工作表,但我需要根据条件将它们发送到另一个工作表(p列)。以下是当前代码 Sub Transfer() Set FormSht = Sheets("Tracker Form") Set MasterSht = Sheets("Consolidated") LR_form = FormSht.Cells(Rows.Count, "A").End(xlUp).Row NR_master =

目前,我有一个某种类型的跟踪表单,当表单中的字段被填充时,它会被发送到合并的工作表,但我需要根据条件将它们发送到另一个工作表(p列)。以下是当前代码

Sub Transfer()
    Set FormSht = Sheets("Tracker Form")
    Set MasterSht = Sheets("Consolidated")

    LR_form = FormSht.Cells(Rows.Count, "A").End(xlUp).Row
    NR_master = MasterSht.Cells(Rows.Count, "A").End(xlUp).Row + 1

    For RowX = 1 To LR_form
        ColX = Application.WorksheetFunction.Match(FormSht.Cells(RowX, "A"), MasterSht.Rows(1), 0)
        MasterSht.Cells(NR_master, ColX) = FormSht.Cells(RowX, "B")
    Next RowX
End Sub
像这样

Sub Transfer(sheet_name As String)

    Set FormSht = Sheets("Tracker Form")
    Set MasterSht = Sheets(sheet_name)

    LR_form = FormSht.Cells(Rows.Count, "A").End(xlUp).Row
    NR_master = MasterSht.Cells(Rows.Count, "A").End(xlUp).Row + 1

    For RowX = 1 To LR_form
        ColX = Application.WorksheetFunction.Match(FormSht.Cells(RowX, "A"), MasterSht.Rows(1), 0)
        MasterSht.Cells(NR_master, ColX) = FormSht.Cells(RowX, "B")
    Next RowX
End Sub

Sub cool_criteria()

'use your filter criterias here, if you have multiple try googeling "vba Select...Case"
If 2 > 1 Then
    sheet_name = "Consolidated"
Else
    sheet_name = "another sheet"
End If

Call Transfer(sheet_name)

End Sub

使用cool_criteria宏设置过滤器,然后调用transfer宏。

我不这么认为:基本上,它应该做的是:在运行宏(我提供的)之后,我会制作另一个宏,从Consolidated选项卡复制粘贴数据,但从p列(业务区域)过滤,并将其复制粘贴到目标工作表(即,在合并选项卡上,过滤到“消费者银行业务”,并且将A:AC中的所有数据(不包括页眉)复制到选项卡“消费者银行业务”(如果所有数据都被复制,只要它们覆盖了工作表中的当前数据即可)