![](/img/trans.png)
[英]Copy Range From One Sheet Paste Part of Range In Same Sheet Based On Cell Value On Another Sheet
[英]Match and paste value from one sheet into another based on a Lookup value
我有兩張紙,賬單和對賬,B 列都有賬單 ID。我需要一個 vba 代碼,它將復制對賬表的 P、Q 和 W 列的值,並將這些值粘貼到 P、Q 和 W 列針對同一賬單 ID 的表單賬單。 在 Sheet Reconciliation Bill Id 從 Row21 開始並且可以是動態的,所以最后一行 function 將被使用。 在表 Bills Bill id 從 B2 開始,可以 go 到 B100000 或更多
Dim wb As Workbook: Set wb = ThisWorkbook
Dim wsDisp As Worksheet: Set wsDisp = wb.Worksheets("Reconciliation")
Dim a As String
Dim b As String
Dim c As String
Dim e As Long
Dim F As String
Application.ScreenUpdating = False
a = wsDisp.Cells(19, 16).Value
b = wsDisp.Cells(19, 17).Value
c = wsDisp.Cells(19, 23).Value
e = MsgBox("Do You Wish to Save Recovery ? " & vbNewLine & "GIDC PAID = " & a & vbNewLine & "GST PAID = " & b & vbNewLine & " LPS PAID = " & c, vbYesNo)
If e = vbNo Then Exit Sub
For i = 21 To 400
Sheets("Bills").Cells(Cells(i, 2), 16) = Sheets("Reconciliation").Cells(i, 16)
Sheets("Bills").Cells(Cells(i, 2), 17) = Sheets("Reconciliation").Cells(i, 17)
Sheets("Bills").Cells(Cells(i, 2), 23) = Sheets("Reconciliation").Cells(i, 23)
Next
Application.ScreenUpdating = True
對賬表
帳單
我有類似的情況,並且有適合我的解決方案,如果 Bill NR 上升,我在這種情況下使用 VLookup。
您可以制作記錄宏來獲取 VLookup 並使用此副本 function 來獲取工作表中的值。
Range("P21").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-10],Reconciliation shee!R2B1:R10000P5,5,FALSE)"
Range("P21").Select
Selection.AutoFill Destination:=Range("P21:P" & LastRow), Type:=xlFillDefault
Range("P21:P" & LastRow).Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.