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