简体   繁体   English

检查其他多个工作表上是否存在excel单元格值-如果是,则返回存在于另一列中的工作表名称

[英]Check if an excel cell value exists on multiple other sheets - and if so return the name of the sheet it exists on in another column

The first two sheets of my workbook each contain a single column, column A, of approximately 2000 values. 我的工作簿的前两页各包含一个单独的列,即A列,其值约为2000。 In addition to these two sheets I have 42 other sheets that each contain anywhere from 20-1500 values, also in a single column A. 除了这两张纸之外,我还有42张其他纸,每张纸都包含20-1500个值,也都在单列A中。

For each of the ~2000 values in column A of sheets 1 and 2 I am trying to check if those values exist in any of the other 42 sheets. 对于工作表1和2的A列中的〜2000值中的每个值,我试图检查这些值是否存在于其他42个工作表中。 If so, I'd like the name of the sheet they exist in to show up in column B. 如果是这样,我希望它们存在的工作表的名称显示在B列中。

So: 所以:

IF sheet1.A1.value EXISTS IN sheet3.A:A
RETURN sheet3.name
ELSE IF sheet1.A1.value EXISTS IN sheet4.A:A
RETURN sheet4.name

etc... 等等...

Sub test()

Dim ws As Worksheet
Dim i As Integer
Dim fRange As Range

'Perform search for Sheet1
Set ws = Sheets("Sheet1")

i = 3

While i <= ActiveWorkbook.Sheets.Count

ws.Select
Set fRange = Range("A1")
fRange.Select

While fRange.Value <> ""

Sheets(i).Select
Range("A1").Select

While ActiveCell.Value <> ""

If ActiveCell.Value = fRange.Value Then

fRange.Offset(0, 1).Value = Sheets(i).Name
ActiveCell.Offset(1, 0).Select

Else

ActiveCell.Offset(1, 0).Select

End If

Wend

Set fRange = fRange.Offset(1, 0)

Wend

i = i + 1

Wend

'Perform search for Sheet2
Set ws = Sheets("Sheet2")

i = 3

While i <= ActiveWorkbook.Sheets.Count

ws.Select
Set fRange = Range("A1")
fRange.Select

While fRange.Value <> ""

Sheets(i).Select
Range("A1").Select

While ActiveCell.Value <> ""

If ActiveCell.Value = fRange.Value Then

fRange.Offset(0, 1).Value = Sheets(i).Name
ActiveCell.Offset(1, 0).Select

Else

ActiveCell.Offset(1, 0).Select

End If

Wend

Set fRange = fRange.Offset(1, 0)

Wend

i = i + 1

Wend

End Sub

Use a For Each loop on the worksheets collection to cycle through the worksheets. 在工作表集合上使用For Each循环在工作表之间循环。 Then use the Range.Find method to check if the cell is found on the worksheet. 然后使用Range.Find方法检查是否在工作表上找到该单元格。 If it is, just write the sheet name to your cover sheet. 如果是这样,只需将工作表名称写到封面。 You can concatenate to one cell, or use a counter to move to the next available column. 您可以连接到一个单元格,或使用计数器移动到下一个可用列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Excel-检查值是否存在于另一个工作表的列中并返回相邻列 - Excel - Check if value exists in a column in another worksheet and return adjacent column 检查工作表(多张工作表)中是否存在值并返回“条目已存在”-Excel - Check if a value exists in a Worksheet (multiple sheets) and return “Entry already exists” - Excel 检查Excel工作表中是否存在列 - check if a column exists in Excel sheet 如何检查其他工作表中是否存在值,然后从行中的另一个单元格输出值 - How to check if value exists in other sheet, then output value from another cell in the row 检查多个工作表中是否存在值 - Check if value exists in multiple sheets 检查列中另一个工作表上是否存在Excel单元格 - 并返回其他列的内容 - Check if an excel cell exists on another worksheet in a column - and return the contents of a different column Excel:检查列中是否已存在单元格值,然后减去并显示另一个值 - Excel: Check if cell value already exists in column, and then substract and show another value 检查两个其他工作表中是否存在单元格值 - checking if cell value exists in two other sheets 检查SQL中是否存在excel单元格值 - check if excel cell value exists in SQL Excel VBA检查工作表是否存在,如果是,则在工作表名称中添加数字 - Excel VBA check if sheet exists and if yes add numeric to sheet name
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM