简体   繁体   English

检查整列以查看文本是否存在。 如果确实如此,则将其记录在其他单元格中

[英]Check an entire column to see if text exists. If it does then document it in a different cell

I am trying to loop through a column to see if a certain series of text exist. 我试图遍历一列,以查看是否存在一定系列的文本。 If it does, then I want to show which text exists in a range. 如果是这样,那么我想显示范围内存在哪些文本。

I have tried for loop and for each cell commands, but I am not sure what else commands to try. 我已经尝试过for循环和每个单元格的命令,但是我不确定还有什么命令可以尝试。

For throughout the entire column shown below, if AH, DF appears I want to write "AutoCAD Construction Issue Hard Copy" in Range B10, and "Digital Files" in B11. 对于下面显示的整个列,如果出现AH,DF,我想在范围B10中编写“ AutoCAD施工问题硬拷贝”,并在B11中编写“数字文件”。 If just "DF, P" appears, I want to write "Digital Files" in Range B10 and Prints in B11. 如果仅出现“ DF,P”,我想在范围B10中写入“数字文件”,并在B11中进行打印。 However if all three of them appear (Like how they do in the picture below) I want to write "AutoCAD Construction Issue Hard Copy" in B10. 但是,如果它们全部都出现了(就像它们在下图中的显示方式一样),我想在B10中编写“ AutoCAD构造问题纸质版”。 "Digital Files" in B11 and Prints in B12. B11中的“数字文件”和B12中的打印。 My problem is, is that whenever I create this list, I want the list to start at B10 and not have a gap in between the list. 我的问题是,每当创建此列表时,我都希望列表从B10开始,并且列表之间不要有空格。 The order of the list must be AutoCAD Construction Issue Hard Copy, Digital Files, and Prints. 列表的顺序必须为AutoCAD Construction Issue硬拷贝,数字文件和打印。

My code is pasted below: 我的代码粘贴在下面:

Sub Descriptions()
    Range("A14:A305").ClearContents

    For r = 14 To Cells(Rows.Count, "B").End(xlUp).Row
        On Error Resume Next  'get rid of that... find error and fix/build logic, don't ignore it

        If Range("A1").Value = "30% Design Review" Or Range("A1").Value = "Final Design Review" Then
            If InStr(Cells(r, "B").Value, "BMC-9") Then
                Cells(r, "E").Value = "Bill of Materials"
                Cells(r, "A").Value = "DF, P"
            ElseIf InStr(Cells(r, "B").Value, "MC-9") Or InStr(Cells(r, "B").Value, "CSR-9") Or InStr(Cells(r, "B").Value, "LC-9") Then
                Cells(r, "A").Value = "DF, P"
            End If
        ElseIf Range("A1").Value = "Construction Submittal" Then
            If InStr(Cells(r, "B").Value, "BMC-9") Then
                Cells(r, "E").Value = "Bill of Materials"
                Cells(r, "A").Value = "DF, P"
            ElseIf InStr(Cells(r, "B").Value, "MC-9") Or InStr(Cells(r, "B").Value, "CSR-9") Or InStr(Cells(r, "B").Value, "LC-9") Then
                Cells(r, "A").Value = "AH, DF"
            End If
        End If
    Next

    For r = 14 To Cells(Rows.Count, "B").End(xlUp).Row
        If Cells(r, "A").Value = "DF, P" Then
            Range("B10").Value = "Digital Files"
            Range("B11").Value = "Prints"
        ElseIf Cells(r, "A").Value = "AH, DF" Then
            Range("B10").Value = "AutoCAD Construction Issue Hard Copy"
            Range("B11").Value = "Digital Files"
        End If
    Next
End Sub

New Edit 04/11/2019 新的编辑04/11/2019

在此处输入图片说明

I may be confused by what you're asking, but, I think you can achieve this with a formula. 我可能对您的要求感到困惑,但是,我认为您可以通过公式来实现。

在此处输入图片说明

... as you can see, it's an array formula so when you go to commit it, make sure you press Shift + Ctrl + Enter , failure to do so will render it useless. ...如您所见,这是一个数组公式,因此当您提交它时,请确保按Shift + Ctrl + Enter ,否则将使其失效。

If it finds your text from within the given range, you'll get a number greater than or equal to 1, from there, you can provide another lookup from another cell to display your text. 如果它在给定范围内找到您的文本,那么您将从那里得到一个大于或等于1的数字,您可以在另一个单元格中提供另一个查找以显示您的文本。

So if I try and use your exact scenario, this is what I came up with ... 因此,如果我尝试使用您的确切方案,这就是我想出的...

例

To make it easier to understand, you can download the example workbook here ... 为了更容易理解,您可以在此处下载示例工作簿...

Example Workbook 示例工作簿

As I said, I think doing all of this as a formula based approach would make it easier to maintain longer term. 正如我所说,我认为将所有这些作为基于公式的方法来进行,将使长期维护变得更加容易。 Maybe that's just me though. 也许那只是我。

I hope that gives you what you want. 我希望这能给您您想要的。

在此处输入图片说明

Sub SeachDesc()
Dim SrchRng As Range, cel As Range
Set SrchRng = Range("A14:A305")
Range("B10:B12").ClearContents
For Each cel In SrchRng
    If cel.Value = "DF, P" Then
        Range("B10").Value = "Digital Files"
        Range("B11").Value = "Print(s)"
    ElseIf cel.Value = "AH, DF" Then
        Range("B10").Value = "AutoCAD Construction Issue Hard Copy"
        Range("B11").Value = "Digital Files"
    End If
Next cel
    If Range("B11").Value = "Print(s)" And Range("B12").Value = "Print(s)" Then
        Range("B10").Value = "AutoCAD Construction Issue Hard Copy"
        Range("B11").Value = "Digital Files"
        Range("B12").Value = "Print(s)"
    End If
End Sub

暂无
暂无

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

相关问题 如何检查单元格中的实际文本是否已经存在于Excel中的列中 - How to check if the actual text in the cell already exists in the column in excel 如何检查元素是否存在于列中,然后在特定单元格中插入带有文本的正方形 - How to check if an element exists in a column, and then insert a square with text in a certain cell 搜索以查看文本是否存在于列中(如果存在),然后计算行数 - Search to see if text exists in a column, if it does then count the row 搜索单元格名称以查看工作表是否存在以及是否存在......? - Searching cell name to see if worksheet exists and if it does…? Excel:搜索一个单元格以查看是否存在整个列中的一个单元格 - Excel: Search A Cell To See If A Cell From An Entire Column Is Present 检查列中是否存在单元格值,返回同一行不同列中的值 - Check if a Cell Value exists in column, return a value in the same row but different column 检查列中另一个工作表上是否存在Excel单元格 - 并返回其他列的内容 - Check if an excel cell exists on another worksheet in a column - and return the contents of a different column 检查“单元格”值是否存在于“列”中,并针对同一事件在同一行但不同列中返回值的总和 - Check if Cell value exists in Column and return a sum for a value in the same row but different column for each occurance 如何将单元格文本转换为整个列的注释? - How to convert cell text to comment for entire column? 检查Row中是否存在Cell值,并返回同一列但不同Row的值 - Check if Cell value exists in Row, and return a value in the same Column but different Row
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM