我试图遍历一个列,看看是否存在某个系列的文本。如果是这样的话,那么我想要显示哪个文本存在于某个范围内。
我尝试过for循环和每个单元格命令,但我不确定还需要尝试什么命令。
对于下面显示的整个专栏,如果AH、DF出现,我想在Range B10中写“B10构建问题硬拷贝”,在B11中写“数字文件”。如果只是"DF,P“出现,我想写”数字文件“的范围B10和打印在B11。但是,如果它们都出现了(就像下面的图片中所显示的那样),我想用AutoCAD编写“B10构建问题硬拷贝”。B11中的“数字文件”和B12中的打印。我的问题是,每当我创建这个列表时,我都希望列表从B10开始,而不是在列表之间出现空白。列表的顺序必须是AutoCAD构建问题硬拷贝、数字文件和打印。
我的代码粘贴在下面:
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新编辑04/11/2019

发布于 2019-04-11 05:15:12
我可能会对你的要求感到困惑,但是,我认为你可以用一个公式来实现这一点。

..。如您所见,这是一个数组公式,所以当您提交它时,请确保按Shift + Ctrl + Enter键,如果不这样做,就会使它变得无用。
如果它在给定的范围内找到您的文本,您将得到大于或等于1的数字,在那里,您可以从另一个单元格中提供另一个查找,以显示您的文本。
所以如果我试着用你的精确场景,这就是我想出来的.

为了便于理解,您可以在这里下载示例工作簿.
正如我所说,我认为将所有这些作为一种基于公式的办法,将使长期保持更容易。也许只有我一个人。
我希望这能给你你想要的。
发布于 2019-04-11 12:58:38

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 Subhttps://stackoverflow.com/questions/55624694
复制相似问题