0

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

行和列的示例如下所示:

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

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

Cat       Jack     Hello
Elephant  Henry    Hello

如果有人对如何这样做有任何建议,将不胜感激。谢谢!

4

2 回答 2

0

为什么不使用 excel 中的内置过滤器,并仅显示符合特定条件的行(您有 countif 的列> X,或按每列)然后打印?

“主页”功能区,面板“编辑、排序和筛选”

于 2013-07-02T18:24:54.123 回答
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
于 2013-07-03T17:57:50.407 回答