我有以下代码来查看范围:LR = Sheets("Consolidated_Data850").Range("A" & Rows.Count).End(xlUp).row
Debug.Print "Savingfile to... " & FileNamePath
If Dir(FileNamePath) <> "" Then Kill FileNamePath
On Error GoTo ErrHandler:
Debug.Print "Generating Email (" & TempFilePath & "ValidPOs.xls" & ")" & Chr(13) & _
ActiveWorkbook.SaveAs FileName:=FileNamePath, FileFormat:=51
EXIT SUB ' if you miss this your error handler below is run irrespective of
' whether there's an error or not.
ErrHandler:
Debug.Print "Error # " & Str(Err.Number) & " was generated " _
& Err.Source & Chr(13) & "Error Line: " & Erl & Chr(13) &
Err.Description
中的任何单元格是否与单元格的值匹配:("B9:B" & LastRowCarArea)
。此单元格的值始终为String,从不为数字。
ThisCellinProjectList
当查找范围中没有与ThisCellinProjectList中的单元格值匹配的单元格时,我收到运行时错误,但无法解决原因。
非常感谢任何帮助。
答案 0 :(得分:0)
您可以使用For Each...Next
语句在ThisCellinProjectList
中查找Range("B9:B" & LastrowCarArea)
。
Dim ThisCellinProjectList As String
Dim LastrowCarArea As Long
Dim myRange As Range
ThisCellinProjectList = Worksheets("Sheet1").Range("B7").Value
LastrowCarArea = Worksheets("Sheet1").Cells(Rows.Count, 2).End(xlUp).Row
Set myRange = Worksheets("Sheet1").Range("B9:B" & LastrowCarArea)
For Each cell In myRange
If cell = ThisCellinProjectList Then
Worksheets("Sheet1").Range("C7") = "TRUE"
' cell.Offset(0, 1) = "TRUE"
End If
Next cell