[英]Lookup in all the sheets for specific text and if match then write value of same row but different column value to master sheet
I found below code relatively useful for me but, not 100% matching with my requirement. 我发现以下代码对我而言相对有用,但并非100%符合我的要求。 please help me on this.
请帮助我。
Problem in this code is:- i have specific text(yes) in specific range(e6:e16). 这段代码中的问题是:-我在特定范围(e6:e16)中有特定的文本(是)。 What I want is to check for only yes word.
我想要的只是检查是的单词。 If found then write value of column A & row, in which yes word found, into master sheet and check it till last sheet.
如果找到,则将在其中找到了单词的A列和行的值写入主表,并检查直到最后一张。
Sub SeachSheets()
Dim FirstAddress As String, WhatFor As String
Dim Cell As Range, Sheet As Worksheet
WhatFor = InputBox("What are you looking for?", "Search Criteria")
If WhatFor = Empty Then Exit Sub
For Each Sheet In Sheets
If Sheet.Name <> "SEARCH" Then
With Sheet.Columns(1)
Set Cell = .Find(WhatFor, LookIn:=xlValues, LookAt:=xlPart)
If Not Cell Is Nothing Then
FirstAddress = Cell.Address
Do
Cell.EntireRow.Copy _
Destination:=Sheets("SEARCH").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
Set Cell = .FindNext(Cell)
Loop Until Cell Is Nothing Or Cell.Address = FirstAddress
End If
End With
End If
Next Sheet
Set Cell = Nothing
End Sub
Any help will be appreciated. 任何帮助将不胜感激。 Thank you.
谢谢。
For one sheet, this is easy to accomplish with a formula alone, eg 对于一张纸,仅使用公式即可轻松完成,例如
= INDEX(1:1,MATCH("yes",5:5,0))
This finds the first instance of yes
in the 5th row of the current sheet, and returns the value in 1st row and in the same column. 这将在当前工作表的第5行中找到
yes
的第一个实例,并在第1行和同一列中返回值。
One option is to have this formula above somewhere on each sheet in your workbook as a "helper cell" (eg cell Z99
) and then have a formula somewhere on your master sheet to check all of these helper cells, eg 一种选择是将此公式放在工作簿中每个工作表上方的某个地方作为“帮助单元格”(例如,单元格
Z99
),然后在您的母版工作表中某个地方的某个位置,以检查所有这些帮助单元格,例如
= IFERROR(Sheet1!Z99,IFERROR(Sheet2!Z99,IFERROR(Sheet3!Z99,IFERROR(...,"no match"))))
Of course, also possible without helper cells at all, but the formula just gets messy: 当然,完全没有辅助单元也是可能的,但是公式变得混乱:
= IFERROR(INDEX(Sheet1!1:1,MATCH("yes",Sheet1!5:5,0)),
IFERROR(INDEX(Sheet2!1:1,MATCH("yes",Sheet2!5:5,0)),
IFERROR(INDEX(Sheet3!1:1,MATCH("yes",Sheet3!5:5,0)),
IFERROR(...,"no match"))))
If you want a way without explicitly calling each sheet, then VBA is probably required. 如果您想要一种方法而无需显式调用每个工作表,则可能需要VBA。 Just posting a solution without VBA to see if this will work for you.
只需发布不带VBA的解决方案,看看是否适合您。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.