根据标准打印行?

时间:2013-07-02 16:52:29

标签: excel printing criteria rows countif

我对excel有点新意,但到目前为止,我已经掌握了一些公式。我所做的是创建了一个countifs公式来搜索列中的某些条件。但是,我想要做的是基于我使用countifs搜索的内容,我想在单独的工作表中显示countifs搜索的行。例如,如果我在A列中搜索并发现A列中的3行中包含单词“Hello”,我想打印出A列中包含“Hello”字样的行。有简单或自动的方法吗?我不想通过过滤器手动完成。如果有人能提供帮助那就太棒了!谢谢!

行和列的示例如下所示:

Animal    Owner    Phrase
Cat       Jack     Hello
Dog       Jill     Bye
Elephant  Henry    Hello

在这种情况下,我会使用countifs来查找“Hello”,它会在单独的工作表中显示行。

Cat       Jack     Hello
Elephant  Henry    Hello

如果有人对如何这样做有任何建议,那将非常感激。谢谢!

2 个答案:

答案 0 :(得分:0)

为什么不在excel中使用内置过滤器,只显示符合特定条件的行(您拥有countif的列是> X,或者是每列),然后打印出来?

“主页”功能区,面板“编辑,排序和过滤

答案 1 :(得分:0)

好的,如果你想在VBA中这样做:

Sub SortByCondition()

Application.ScreenUpdating = False

Dim i As Integer, r As Integer
Dim rFirst As Integer, rLast As Integer
Dim wSin As Worksheet, wSout As Worksheet ' I like to have variables when working on multiple sheets for clarity and ease of use

Set wSin = Sheets("Raw") ' The sheet where you have unsorted data
Set wSout = Sheets("Sorted") ' The sheet where you will copy the sorted data

' This is to find the first and last row in your table... there are many other ways to do it
With wSin.Cells(1, 1).CurrentRegion  ' Replace with first cell in your table
    rFirst = .Rows.Row + 1  ' Assumes the first line of your table is the header
    rLast = .Rows.Count + .Rows.Row - 1
End With

r = 2 ' We'll start copy on row 2 in the output sheet

For i = rFirst To rLast Step 1

    If wSin.Cells(i, 3).Value = "Hello" Then  ' I'm assuming we test for 'Hello' being in column C

        Range(wSin.Cells(i, 1), wSin.Cells(i, 3)).Copy wSout.Cells(r, 1)   ' We'll copy in columns A to C in the output sheet
        r = r + 1

    End If

Next i


Application.ScreenUpdating = True

End Sub
相关问题