我无法理解为什么Elseif-Statement不起作用。我已经测试了第一个If-Statement并且它的工作方式与预期一致,但是Elseif-Statement没有,尽管语法有点像以前一样。 有人可以发现我的错误吗?
/ edit:这是完整的代码。对不起,我认为如果我发布我的问题会更容易,因为之前的代码就像魅力一样,我不认为它会导致任何错误。还在学习这个。
phone_category_data = requests.get(phone_category_url)
base_category_soup = soup(phone_category_data.content, "html.parser")
div_list = base_category_soup.find_all("div")
for div in div_list:
if div["class"]:
if div['class'][0] == 'makers':
print div.text
答案 0 :(得分:0)
看看上面的评论。
有时间和地点使用On Error Resume Next
,但应尽快跟进On Error Goto 0
。否则会覆盖简单的错误,并且无法解释代码无法正常工作的原因。
关于这段代码。您不能将多范围引用等同于单个值,它会给您Type Mismatch
错误。
所以你要循环一个范围,数组会更好,用它来一次找到一个单元格。
另外,Else有点错误,你不需要在Else中使用布尔语句,它就是全部。
使用它:
Dim lastRow As Long
Dim i As Long
lastRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
lastrow1 = Sheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).Row
Source1 = Sheets("Sheet2").Range("E3:J" & lastrow1)
Set A = Sheets("Sheet1").Range("Q2:Q" & lastRow)
Set B = Sheets("Sheet1").Range("E2:E" & lastRow)
Set C = Sheets("Sheet1").Range("F2:F" & lastRow)
For i = 2 To lastRow
If C(i).Value <> "" And B(i).Value <> "" Then
A(i).Value = C(i).Value
ElseIf C(i).Value = "" And B(i).Value <> "" Then
A(i).Value = B(i).Value
Else
A(i).Value = Application.WorksheetFunction.VLookup(A(i).Value, Source1, 6, False)
End If
Next i