[英]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.