简体   繁体   English

如果某些列在值之间,则将整个行复制到 Excel 中的新工作表

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

相关问题 Excel将列的某些值复制到另一个工作表 - Excel Copy certain values of Column to another sheet Excel VBA-在特定列中搜索#N / A,将整行复制到新工作表中并删除行 - Excel VBA - Search certain column for a #N/A, copy entire row to new sheet and delete row Excel VBA在列中搜索值,然后将所有匹配值的行复制到新表中 - Excel VBA Search for a value in a column and copy row to new sheet for all matching values 将 excel 值复制到新工作表 - Copy excel values to a new sheet Excel VBA-在列中搜索某些条件,然后将该行复制到新工作表中 - Excel VBA - Search for certain criteria in a column and copy that row to new worksheet Excel宏从一张工作表中搜索第1行中的某些文本,复制该文本下的列,然后粘贴到另一张工作表中 - Excel Macro to search certain texts in row 1 from one sheet, copy the column under the text, and paste to a different sheet 将某些行复制到excel中的新工作表的公式 - Formula to copy certain rows to a new sheet in excel 在列中搜索值并将行复制到新工作表 - Search for a value in a column and copy row to new sheet 将 excel 工作表中的行复制到新工作表中,而不复制双打 - Copy row from excel sheet into a new sheet withou copying doubles 如果其中的列包含指定值(新工作表中另一列的值),如何将行复制到另一个 Excel 工作表上? - How to copy a row onto another excel worksheet if a column in it contains a specified value (of another column in the new sheet)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM