将某些行复制到excel中的新工作表的公式

将某些行复制到excel中的新工作表的公式,excel,excel-formula,Excel,Excel Formula,我正在寻找一个公式,该公式将根据某些条件(特别是,无论行是否高亮显示)将行从一个工作表复制到另一个工作表。我们该怎么做呢?我最后只使用了VBA。我必须在开始时使用“是/否”单元格来指定是否高亮显示一行,以便在任何人更改值时自动更新该行 Sub Autosort() Application.ScreenUpdating = False Sheets(2).Select Range(Cells(2, 1), Cells(Rows.Count, Columns.Count)).Clear Sheets

我正在寻找一个公式,该公式将根据某些条件(特别是,无论行是否高亮显示)将行从一个工作表复制到另一个工作表。我们该怎么做呢?

我最后只使用了VBA。我必须在开始时使用“是/否”单元格来指定是否高亮显示一行,以便在任何人更改值时自动更新该行

Sub Autosort()
Application.ScreenUpdating = False
Sheets(2).Select
Range(Cells(2, 1), Cells(Rows.Count, Columns.Count)).Clear
Sheets(3).Select
Range(Cells(2, 1), Cells(Rows.Count, Columns.Count)).Clear
Sheets(1).Select
FinalColumn = Cells(1, 1).End(xlToRight).Column
FinalRow = 1
For x = 1 To FinalColumn
    thisRow = Cells(Rows.Count, x).End(xlUp).Row
    If thisRow > FinalRow Then
        FinalRow = thisRow
    End If
Next x

For x = 2 To FinalRow
    IsCompleted = Cells(x, 1).ValueThen
    If IsCompleted = "Yes" Then
        Cells(x, 1).Resize(1, FinalColumn).Interior.ColorIndex = xlColorIndexNone
        Cells(x, 1).Resize(1, FinalColumn).Copy
        Sheets(2).Select
        NextRow = Cells(Rows.Count, 1).End(xlUp).Row + 1
        Cells(NextRow, 1).Select
        ActiveSheet.Paste
        Sheets(1).Select
    ElseIf IsCompleted = "No" Then
        Cells(x, 1).Resize(1, FinalColumn).Interior.ColorIndex = 6
        Cells(x, 1).Resize(1, FinalColumn).Copy
        Sheets(3).Select
        NextRow = Cells(Rows.Count, 1).End(xlUp).Row + 1
        Cells(NextRow, 1).Select
        ActiveSheet.Paste
        Sheets(1).Select
    Else
        Cells(x, 1).Value = "No"
        Cells(x, 1).Resize(1, FinalColumn).Interior.ColorIndex = 6
        Cells(x, 1).Resize(1, FinalColumn).Copy
        Sheets(3).Select
        NextRow = Cells(Rows.Count, 1).End(xlUp).Row + 1
        Cells(NextRow, 1).Select
        ActiveSheet.Paste
        Sheets(1).Select
    End If
Next x
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub

我最后只使用了VBA。我必须在开始时使用“是/否”单元格来指定是否高亮显示一行,以便在任何人更改值时自动更新该行

Sub Autosort()
Application.ScreenUpdating = False
Sheets(2).Select
Range(Cells(2, 1), Cells(Rows.Count, Columns.Count)).Clear
Sheets(3).Select
Range(Cells(2, 1), Cells(Rows.Count, Columns.Count)).Clear
Sheets(1).Select
FinalColumn = Cells(1, 1).End(xlToRight).Column
FinalRow = 1
For x = 1 To FinalColumn
    thisRow = Cells(Rows.Count, x).End(xlUp).Row
    If thisRow > FinalRow Then
        FinalRow = thisRow
    End If
Next x

For x = 2 To FinalRow
    IsCompleted = Cells(x, 1).ValueThen
    If IsCompleted = "Yes" Then
        Cells(x, 1).Resize(1, FinalColumn).Interior.ColorIndex = xlColorIndexNone
        Cells(x, 1).Resize(1, FinalColumn).Copy
        Sheets(2).Select
        NextRow = Cells(Rows.Count, 1).End(xlUp).Row + 1
        Cells(NextRow, 1).Select
        ActiveSheet.Paste
        Sheets(1).Select
    ElseIf IsCompleted = "No" Then
        Cells(x, 1).Resize(1, FinalColumn).Interior.ColorIndex = 6
        Cells(x, 1).Resize(1, FinalColumn).Copy
        Sheets(3).Select
        NextRow = Cells(Rows.Count, 1).End(xlUp).Row + 1
        Cells(NextRow, 1).Select
        ActiveSheet.Paste
        Sheets(1).Select
    Else
        Cells(x, 1).Value = "No"
        Cells(x, 1).Resize(1, FinalColumn).Interior.ColorIndex = 6
        Cells(x, 1).Resize(1, FinalColumn).Copy
        Sheets(3).Select
        NextRow = Cells(Rows.Count, 1).End(xlUp).Row + 1
        Cells(NextRow, 1).Select
        ActiveSheet.Paste
        Sheets(1).Select
    End If
Next x
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub

检查这一点:使用vba更容易、更好。公式需要是数组,并且基于列中的值而不是颜色。公式本身无法检查单元格的属性。如何确定单元格是否高亮显示?如果是手动完成的,则可能需要VBA。如果是条件格式,您可以使用该条件来帮助确定要执行的操作…显然VBA是最好的解决方案。作为excel的一般经验法则,我只在需要更改公式所在单元格的情况下使用公式。在条件下复制单元格对于公式来说有点太复杂了。请检查我们的:使用vba更容易、更好。公式需要是数组,并且基于列中的值而不是颜色。公式本身无法检查单元格的属性。如何确定单元格是否高亮显示?如果是手动完成的,则可能需要VBA。如果是条件格式,您可以使用该条件来帮助确定要执行的操作…显然VBA是最好的解决方案。作为excel的一般经验法则,我只在需要更改公式所在单元格的情况下使用公式。在条件下复制单元格对于公式来说有点太复杂了。