简体   繁体   English

基于一个单元格值复制行并引用另一个单元格值并粘贴到新工作表上

[英]Copy rows based on one cell value and in reference to another cell value and paste on a new sheet

I have to create a report where I get a raw data with a list of transactions, I need my macro to send each transaction to its respective sheets based on if Portfolio name at C Column 我必须创建一个报告,在其中我获得带有事务列表的原始数据,我需要我的宏根据C列中的项目组合名称将每个事务发送到其各自的表

I manged to do that, but now I need Transaction of Nokia that fall under 'Cash' from the below given reference sheet, to paste under sheet "Nokia - Cash" 我这样做了,但现在我需要从下面给出的参考表中的“现金”下的诺基亚交易,粘贴在“诺基亚 - 现金”表下

原始数据工作簿更新

参考表

Can someone please help me build the 2nd part of my code which helps to move the if C=Nokia and J = Semi Paid then move to Nokia - Cash? 有人可以帮我构建我的代码的第二部分,这有助于移动if C = Nokia和J = Semi Paid然后转移到Nokia - Cash?

It is similar to the previous question I have answered. 它类似于我之前回答的问题。

You don't have to worry about creating the sheets and naming them, the code handles it. 您不必担心创建工作表并命名它们,代码会处理它。 It also skips the items which are not found in reference sheet. 它还会跳过参考表中未找到的项目。

It matches the description item with item in your reference sheet , then concats card name with the matched item's category name in order to name the relevant sheet. 它将描述项参考表中的项匹配,然后将卡名称匹配项的类别名称进行联合 ,以便命名相关表。 If this sheet does not exist, it creates and pass the row data, otherwise simply pass the row data. 如果此工作表不存在,则会创建并传递行数据,否则只需传递行数据。

Sub MyClients()
Dim lastrow As Long, lastcol As Long, matchrow As Long, i As Long, j As Long
Dim wsname As String
lastrow = Worksheets("Raw").Cells(Worksheets("Raw").Rows.Count, 1).End(xlUp).Row
lastcol = Worksheets("Raw").Cells(1, Worksheets("Raw").Columns.Count).End(xlToLeft).Column

Application.ScreenUpdating = False
For i = 2 To lastrow
    On Error Resume Next
    matchrow = Application.WorksheetFunction.Match(Worksheets("Raw").Cells(i, 10).Value, Worksheets("Reference").Range("A:A"), 0)
    If Err.Number = 1004 Then
        MsgBox "Couldn't find item: '" & Worksheets("Raw").Cells(i, 10).Value & "' within reference sheet. Skipping row no: " & i
        GoTo skip:
    End If
    wsname = Worksheets("Raw").Cells(i, 3).Value & " - " & Worksheets("Reference").Cells(matchrow, 2).Value
    On Error Resume Next
    Worksheets(wsname).Cells(Worksheets(wsname).Rows.Count, 1).End(xlUp).Offset(1, 0) = Worksheets("Raw").Cells(i, 1).Value
    For j = 1 To lastcol - 1
        Worksheets(wsname).Cells(Worksheets(wsname).Rows.Count, 1).End(xlUp).Offset(0, j) = Worksheets("Raw").Cells(i, j).Value
    Next j
    If Err.Number = 9 Then
        Sheets.Add(After:=Sheets(Sheets.Count)).Name = wsname
        For j = 1 To lastcol
            Worksheets(wsname).Cells(1, j) = Worksheets("Raw").Cells(1, j).Value
        Next j
        Worksheets(wsname).Cells(Worksheets(wsname).Rows.Count, 1).End(xlUp).Offset(1, 0) = Worksheets("Raw").Cells(i, 1).Value
        For j = 1 To lastcol - 1
            Worksheets(wsname).Cells(Worksheets(wsname).Rows.Count, 1).End(xlUp).Offset(0, j) = Worksheets("Raw").Cells(i, j).Value
        Next j
    End If
skip:
Next i
Worksheets("Raw").Activate
Application.ScreenUpdating = True
End Sub

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

相关问题 根据单元格值复制行并粘贴到新工作表上 - Copy rows based on cell value and paste on a new sheet 根据单元格值复制行并粘贴到具有相同单元格值名称的新工作表上 - Copy rows based on cell value and paste on a new sheet with same cell value name 根据对一个单元格值的搜索将新行复制到 Excel 工作表中 - Copy new rows into excel sheet based on search on one cell value 从另一张纸上的单元格值复制同一张纸中范围的一部分的粘贴范围 - Copy Range From One Sheet Paste Part of Range In Same Sheet Based On Cell Value On Another Sheet 根据单元格值将数据从一张表复制并粘贴到另一张表 - Copy and paste data from one sheet to another sheet(s) based on cell value 根据单个单元格值将项目复制/粘贴到另一个工作表上 - Copy/Paste Item onto another sheet based on a single cell value 根据超链接单击将单元格值复制并粘贴到另一个工作表 - Copy and paste cell value to another sheet based on hyperlink click 从一个单元格中查找值,从该单元格附近的单元格中复制值,然后将其粘贴到另一张纸上 - Find value from one cell, copy value from cell near to that cell and paste it to another sheet 根据单元格值复制和粘贴行 - Copy and Paste Rows based on cell value 根据单元格值(日期)复制和粘贴行 - Copy and paste rows based on cell value (date)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM