[英]Copy enitire row to new sheet in excel if certain column is between values
I have a huge excel file with data, and i want to create a new sheet with only the rows that one of their columns (column "Date" in my example) is between the values 5 to 10.我有一个包含数据的巨大 excel 文件,我想创建一个新工作表,其中仅包含其中一列(在我的示例中为“日期”列)在值 5 到 10 之间的行。
For example,例如,
I have data like this:我有这样的数据:
Date m X Y
4 30 5 7
7 31 5 7
7 32 5 7
9 33 5 7
10 34 5 7
2 35 5 7
And I want to make new sheet like this:我想制作这样的新表:
Date m X Y
7 31 5 7
7 32 5 7
9 33 5 7
Any leads ?任何线索?
How's something like this:怎么样是这样的:
Sub test()
Dim lastRow As Integer, newLastRow As Integer, lastCol As Integer
Dim ws As Worksheet, newWS As Worksheet
Set ws = ActiveSheet
Set newWS = Sheets.Add
newWS.Name = "Parsed Info"
Dim cel As Range, rng As Range
newLastRow = 1
With ws
lastRow = .Cells(1, 1).End(xlDown).Row
For Each cel In .Range(.Cells(1, 1), .Cells(lastRow, 1))
If 10 >= cel.Value And cel.Value >= 5 Then
lastCol = .Cells(cel.Row, 1).End(xlToRight).Column
Set rng = .Range(.Cells(cel.Row, 1), .Cells(cel.Row, lastCol))
rng.Copy
With newWS
.Range(.Cells(newLastRow, 1), .Cells(newLastRow, lastCol)).PasteSpecial
End With
newLastRow = newLastRow + 1
End If
Next cel
End With
Application.CutCopyMode = False
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.