VBA基于filter进行复制和粘贴

感谢任何人的帮助创buildVBA代码执行复制和粘贴function的基础上select的特定标准。 我认为它需要是一个VBA脚本,因为我有一个macros来清除新PO的选项卡中的数据,一旦“订单”被写入并且信息被复制到PO的选项卡。 我目前有一个完美的复制和粘贴脚本,并将3个单元格从“新buildPO”选项卡复制到“PO”选项卡,请参阅下面的脚本。 这是通过一个button来执行“复制数据”。

我现在正在寻找一个VBA脚本,它将根据G列选定的类别从NEW PO选项卡过滤/validation数量(列S)Z栏和扩展成本,并将其粘贴到订单正确月份下的PO选项卡正在写入,这是由新PO选项卡上单元格T12中的开始date确定的。 另外的挑战是,当类别从00改变到01时,它应该下降到PO的选项卡上的下一行并改变类别。

以下是讨论中的两个选项卡的屏幕截图,并再次感谢如何进行此项工作。

PO的标签

新PO的标签

编辑6/7

Sub Copy_Data() Dim Count, Qty As Long Dim CatRng, MonthRng, SDate, CxlDate, PoNumb, Vendor As Range Dim Total As Currency Dim StrTarget As String Dim Row, PORow, Col As Integer Set CatRng = Sheets("NEW PO").Range("G20:G43") Set MonthRng = Sheets("POs").Range("L122:W122") StrTarget = Sheets("New PO").Range("V12") Set SDate = Sheets("New PO").Range("T12") Set CxlDate = Sheets("New PO").Range("T13") Set PoNumb = Sheets("New PO").Range("N10") Set Vendor = Sheets("New PO").Range("D14") Count = 0 For Count = 0 To 99 Total = 0 Qty = 0 'So that the values reset each time the cat changes For Each cell In CatRng 'To get the row number then total the required information If cell.Value = Count Then Row = cell.Row Qty = Qty + Sheets("NEW PO").Range("S" & Row).Value Total = Total + Sheets("NEW PO").Range("Z" & Row).Value 'I guessed ext cost only as it has been totaled at the bottom, 'this is easily changed though End If Next cell 'Now put the totals into a PO only if there is a quantity of items If Qty > 0 Then PORow = Sheets("POs").Range("K1048576").End(xlUp).Row + 1 'I'll let you sort the PO number and other fields out but the main 3 are done below With Sheets("POs") .Range("I" & PORow).Value = Qty .Range("K" & PORow).Value = Count .Range("C" & PORow).Value = SDate .Range("D" & PORow).Value = CxlDate .Range("B" & PORow).Value = PoNumb .Range("F" & PORow).Value = Vendor 'My understanding here is that the target month in T12 is in the same format as 'the anticipated Receipt month, I hope this is what you were looking for For Each cell In MonthRng If cell.Value = StrTarget Then Col = cell.Column .Cells(PORow, Col).Value = Total 'Used .cells here as both column and row are now integers '(only way i can ever get it to work) End If Next cell End With End If Next Count End Sub 

好的,这似乎符合你想要做的事情,请让我知道,如果没有。

这会有点长,因为我只是在会议之间把这件事情凑在一起,但是却完成了这项工作。 您可以使用行和列索引来操纵您希望拉动的任何其他数据,或者修改您希望累计的成本。

 Sub Test() Dim Count, Qty As Long Dim CatRng, MonthRng As Range Dim Total As Currency Dim Row, PORow, Col As Integer Set CatRng = Sheets("NEW PO").Range("G19:G43") Set MonthRng = Sheets("POs").Range("L122:W122") Count = 0 For Count = 0 To 99 Total = 0 Qty = 0 'So that the values reset each time the cat changes For Each Cell In CatRng 'To get the row number then total the required information If Cell.Value = Count Then Row = Cell.Row Qty = Qty + Sheets("NEW PO").Range("T" & Row).Value Total = Total + Sheets("NEW PO").Range("AA" & Row).Value 'I guessed ext cost only as it has been totaled at the bottom, 'this is easily changed though End If Next Cell 'Now put the totals into a PO only if there is a quantity of items If Qty > 0 Then PORow = Sheets("POs").Range("J1048576").End(xlUp).Row + 1 'I'll let you sort the PO number and other fields out but the main 3 are done below With Sheets("POs") .Range("I" & PORow).Value = Qty .Range("J" & PORow).Value = Count 'My understanding here is that the target month in T12 is in the same format as 'the anticipated Receipt month, I hope this is what you were looking for For Each Cell In MonthRng If Cell.Value = .Range("T12").Value Then Col = Cell.Column .Cells(PORow, Col).Value = Total 'Used .cells here as both column and row are now integers '(only way i can ever get it to work) End If Next Cell End With End If Next Count End Sub