我需要扫描列 B 来查找与单元格 AL2 中找到的具有相同左侧字符的任何值,字符串的长度在 AR1 中找到。如果 Col B 中的左侧值与 AL2 中的值匹配,我需要将该行中的值从 Col B 复制到 col G。复制到 Col At 中,启动 AT6 并继续向下,直到检查完 Col C 中的所有值为止。第一张图是要扫描的数据,第二张图是我想要宏吐出的内容
这是我录制的修改后的宏。我在 IF 语句上收到运行时 13 错误。关于如何清理它有什么想法吗?
Sub GenerateSummaryPage()
'
' scans B column for combiner box numbers
Application.ScreenUpdating = False
Dim dlen As String
Worksheets("HR-Cal").Activate
dlen = Worksheets("HR-Cal").Range("AR2")
r = ActiveCell.Row
For lrow = Cells(Cells.Rows.Count, "B").End(xlUp).Row To 7 Step -1
'checks curent row for box name in cell AL2
'copies values from col B to col G in that row to into Col AT, starting at AS6
If Left(Cells(lrow, "B"), dlen) = ActiveSheet.Range("AL2").Text Then Range("B" & r).Rows.Select
'If Left(Cells(lrow, "B"), dlen) = Range("AL2").Value Then Range("B" & r & ":G" & r).Select
Selection.Copy
Range("AT100000").End(xlUp).Offset(1, 0).PasteSpecial (xlPasteAll)
Next lrow
Application.ScreenUpdating = True
'insert rows for inverter headers
End Sub
最佳答案
你应该试试这个。
If Left(Cells(lrow, "B"), dlen) = ActiveSheet.Range("AL2").Text Then
Range(Cells(lrow, "B"), Cells(lrow, "G")).Value = Range(Cells(lrow, "AT"), Cells(lrow, "AY")).Value
End if
如果这不起作用,在 if 之前您可以尝试检查 lrow 和 dlen 的值以确保它们具有正确的值。
请告诉我这是否适合您
关于excel - 扫描列以查找匹配的文本并将结果粘贴到另一列中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32743063/