[英]Copy enitire row to new sheet in excel if certain column is between values
我有一個包含數據的巨大 excel 文件,我想創建一個新工作表,其中僅包含其中一列(在我的示例中為“日期”列)在值 5 到 10 之間的行。
例如,
我有這樣的數據:
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
我想制作這樣的新表:
Date m X Y
7 31 5 7
7 32 5 7
9 33 5 7
任何線索?
怎么樣是這樣的:
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.