![](/img/trans.png)
[英]Excel: If Cell in Column = text value of X, then display text (in the same row, but different column) on another sheet
[英]Lookup in all the sheets for specific text and if match then write value of same row but different column value to master sheet
我发现以下代码对我而言相对有用,但并非100%符合我的要求。 请帮助我。
这段代码中的问题是:-我在特定范围(e6:e16)中有特定的文本(是)。 我想要的只是检查是的单词。 如果找到,则将在其中找到了单词的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
任何帮助将不胜感激。 谢谢。
对于一张纸,仅使用公式即可轻松完成,例如
= INDEX(1:1,MATCH("yes",5:5,0))
这将在当前工作表的第5行中找到yes
的第一个实例,并在第1行和同一列中返回值。
一种选择是将此公式放在工作簿中每个工作表上方的某个地方作为“帮助单元格”(例如,单元格Z99
),然后在您的母版工作表中某个地方的某个位置,以检查所有这些帮助单元格,例如
= IFERROR(Sheet1!Z99,IFERROR(Sheet2!Z99,IFERROR(Sheet3!Z99,IFERROR(...,"no match"))))
当然,完全没有辅助单元也是可能的,但是公式变得混乱:
= 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"))))
如果您想要一种方法而无需显式调用每个工作表,则可能需要VBA。 只需发布不带VBA的解决方案,看看是否适合您。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.