简体   繁体   English

Excel VBA - 根据条件文本字符串将数据范围从一个工作表传输到另一个工作表

[英]Excel VBA - Transfer Data range from one sheet to another based on conditional text string

I am new to macros and am trying to transfer a data range from one worksheet to another based on a conditional text string. 我是宏的新手,我正在尝试根据条件文本字符串将数据范围从一个工作表传输到另一个工作表。

Data in "inquires" sheet (Range "A5:G1200") needs to transfer to "quotes" sheet based on if column Range "K6:K1200" in "inquiries" sheet is a text string "Y" or "N". “查询”表(范围“A5:G1200”)中的数据需要根据“查询”表中的列范围“K6:K1200”是文本字符串“Y”还是“N”而转移到“引号”表。 If text is "Y" we want the data rows with "y" to transfer, if the text is "N" we do not want rows with "N" to transfer. 如果文本为“Y”,我们希望传输带有“y”的数据行,如果文本为“N”,我们不希望传输带“N”的行。

Once the data range with "Y" transfers over to "quotes" sheet, we then need to transfer data from "Quotes" sheet (Range "A5:G1200" & and separate Range "L5:M1200") to "orders" sheet based on if column range "N6:N1200" in "quotes" sheet is a text string "Rec'vd" or "Closed". 一旦带有“Y”的数据范围转移到“报价”表,我们就需要将数据从“报价”表(范围“A5:G1200”&和单独的范围“L5:M1200”)传送到“订单”表单如果“引号”表中的列范围“N6:N1200”是文本字符串“Rec'vd”或“已关闭”。 Same as above, If text is "Rec'vd" we want the data rows with "rec'vd" to transfer. 与上面相同,如果文本是“Rec'vd”,我们希望传输带有“rec'vd”的数据行。 If "Closed" then no data from "closed" rows should transfer. 如果“已关闭”,那么“关闭”行中的数据不应传输。

Once all data is transferred to all 3 sheets based on text conditions. 根据文本条件将所有数据传输到所有3张纸。 I want to have a 4th sheet that will filter this data based on a date range. 我想要第4张表格,根据日期范围过滤此数据。 I want to be able to type in a date range and then all data from each sheet ("inquires", "quotes", & "orders") to filter to that "master" 4th sheet. 我希望能够输入日期范围,然后输入每张表中的所有数据(“查询”,“引号”和“订单”)以过滤到“主”第4页。 Each data sheet should have its own area (one below the other) on the master sheet to filter to. 每个数据表应在主表上有自己的区域(一个在另一个下面)以进行过滤。

Here is what I have so far.. 这是我到目前为止...

Sub TransferTest1()
    Dim INQUIRE As Worksheet
    Dim QUOTE As Worksheet
    Dim ORDER As Worksheet
    Dim YString As String
    Dim RecString As String

    Set INQUIRE = ActiveWorkbook.Sheets("Inquiries")
    Set QUOTE = ActiveWorkbook.Sheets("Quotes")
    Set ORDER = ActiveWorkbook.Sheets("Orders")

    If INQUIRE.Range("K6:K1200") = "Y" Then
        INQUIRE.Range("A5:G1200").Copy QUOTE.Range("A5")
    End If

    If QUOTE.Range("N6:N1200") = "Rec'vd" Then
        QUOTE.Range("A5:G1200").Copy ORDER.Range("A5")
        QUOTE.Range("L5:M1200").Copy ORDER.Range("K5")
    End If
End Sub

I appreciate any and all help! 我感谢任何和所有的帮助!

Robert Smithey 罗伯特Smithey

This is a typical use-case for Autofilter . 这是Autofilter的典型用例。

With INQUIRE.Range("A4:K1200")
    .AutoFilter 11, "Y"
    .offset(1).Resize(, 7).Copy QUOTE.Range("A5")  ' columns A:G
    .AutoFilter
End With

With QUOTE.Range("A4:N1200")
    .AutoFilter 14, "Rec'vd"
    .offset(1).Resize(, 7).Copy ORDER.Range("A5") ' columns A:G
    .offset(1).Resize(, 2).offset(11).Copy ORDER.Range("K5")  ' columns L:M
    .AutoFilter
End With

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 VBA-根据文本将数据从一张纸传输到另一张纸,然后放入另一张纸的特定位置 - VBA- Transfer data from one sheet to another based on text and placing in into a specific location in the other sheet VBA将数据从一张纸传输到另一张纸 - VBA Transfer of data from one sheet to another 如何根据特定条件使用 VBA 将信息从 Excel 中的一张工作表传输到另一张工作表? - How can I transfer information from one sheet in Excel to another using VBA based on specific conditions? Excel VBA数据从一张纸转移到另一张纸错误仅标题复制没有任何数据 - excel vba data transfer from one sheet to another error only title copy no any data VBA根据参考单元格中的匹配值将数据从一个范围移动到另一个图纸范围 - VBA move data from one range to another sheet range based on matching values in reference cell 根据Excel中的组合框值将数据从一张纸传输到另一张纸 - Transfer data from from one sheet to another based on combobox value in excel 将数据从工作表传输到另一工作表的 VBA 代码 - A VBA code to transfer data from a sheet to another one excel vba 范围从一张纸复制到另一张纸(错误 1004) - excel vba range copy from one sheet to another (error 1004) Excel 如何将数据从一张纸传输到另一张纸 - Excel how to transfer data from one sheet to another sheets 如何在Excel VBA中将hlookup与另一张工作表中的一系列数据一起使用? - how to use hlookup in Excel VBA with a range of data from another sheet?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM