简体   繁体   English

如何根据多个单元格值将一个工作表中的特定行复制到另一个工作表?

[英]How can I copy specific rows in one worksheet to another based on multiple cell values?

I have only basic vba knowledge and I am looking for help.我只有基本的 vba 知识,我正在寻求帮助。 I have searched this topic but I can't find anything for my specific needs.我已经搜索了这个主题,但找不到任何满足我特定需求的东西。 I have to work with spreadsheets generated by a piece of test equipment.我必须使用由一台测试设备生成的电子表格。 I am trying to look at the values in each row in starting in column C up to as many as 60 columns, which varies.我试图查看从 C 列开始的每一行中的值,最多可达 60 列,这会有所不同。 If the value of any cell from C7 on in not “”, I want to copy the entire row to a new sheet.如果 C7 上的任何单元格的值不是“”,我想将整行复制到新工作表。 The data in each cell will be either a positive or negative number with 3 decimal places.每个单元格中的数据将是带有 3 个小数位的正数或负数。 I may have as many as 3500 rows to go through with 10-20 rows that have any information that I would like to move.我可能有多达 3500 行到 go 到 10-20 行,其中包含我想要移动的任何信息。 Example In the example screenshot, I only care about copying row 7 and 15示例在示例屏幕截图中,我只关心复制第 7 行和第 15 行

I came up with this but I'm sure there has to be a more efficient solution我想出了这个,但我确信必须有一个更有效的解决方案

    Sub Splice()
   
    Dim lr As Integer 'last row
    Dim lc As Integer 'last column
    Dim r As Integer 'row number
    
    With Worksheets("Splice loss")
    lr = .Cells(.Rows.Count, "A").End(xlUp).Row 'count number of rows
    lc = .Cells(1, Columns.Count).End(xlToLeft).Column 'count number of columns
    End With
    
    i = 7 'first row number in destination sheet
        
    For r = 7 To lr
    With Worksheets("Splice loss")
    If WorksheetFunction.Sum(Range(Cells(r, 3), (Cells(r, lc)))) <> 0 Then 'check values in each row
    Range(Cells(r, 3), Cells(r, lc)).EntireRow.Copy Worksheets("Splices").Range("A" & i) 'copy row with data to new sheet
        
    i = i + 1
    End If
    End With
    Next
    

End Sub

暂无
暂无

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

相关问题 如何根据该行中的单元格值复制特定行并将其粘贴到匹配的工作表 - How can I copy specific rows based on a cell value in that row and paste it to a matching worksheet 单击特定单元格时,如何将一个单元格的信息复制到另一个工作表上的单元格? - How do I copy information of one cell to a cell on another worksheet, when a specific cell is clicked? 如果工作表中的 3 列值相同,如何将单元格内容从多行复制到一个单元格中? - How to copy cell contents from multiple rows into one cell if 3 column values are the same within a worksheet? 将基于多个条件的行从一个工作表复制到另一个VBA - Copy Rows Based On Multiple Criteria from one Worksheet to Another VBA 将单元格值从一个工作表复制到另一个工作表 - Copy cell values from one worksheet to another 如何基于特定列而不是可变行中单元格的值命名工作表,同时创建/复制工作表? - How can I create/copy a worksheet while naming it based on the value of a cell in a specific column but variable row? 如何将特定列和行复制到另一个工作表 - How do I copy to another worksheet specific columns and rows 根据另一个工作表中的单元格值隐藏一个工作表中的行 - Hide rows in one worksheet based on a cell value in another worksheet 将多行从一个工作表复制到另一个工作表 - Copy multiple rows from one worksheet to another worksheet 根据4个单元格特定的条件将整个Excel行从一个工作表复制到另一个工作表 - Copy entire Excel row from one worksheet to another based on 4 cell specific critera
相关标签
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM