![](/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.