我是个新手,但到目前为止我已经掌握了一些公式的诀窍。我所做的是创建一个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
如果任何人对如何做到这一点有任何建议,将不胜感激。谢谢!
发布于 2013-07-02 18:24:54
为什么不使用excel中的内置筛选器,只显示符合特定条件的行( countif为> X的列,或者按每列显示),然后打印出来?
“主页”功能区,面板“编辑、排序和筛选
发布于 2013-07-03 17:57:50
好的,如果您想在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
https://stackoverflow.com/questions/17431342
复制相似问题