[英]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 ... 为了更容易理解,您可以在此处下载示例工作簿...
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.