在Excel中,如果第V列中的单元格不等于F或V,我只是想删除一行。此代码删除所有内容。它必须是愚蠢的东西,但我看不到它。请帮忙!
For i = RowCount To 1 Step -1
If Range("V" & i).Value <> "F" Or Range("V" & i).Value <> "V" Then Rows(i).Delete
Next i
答案 0 :(得分:1)
您的逻辑似乎不正确。通过将or
更改为and
,您将评估正确的布尔算法。
目前,您正在检查始终为假的not "v"
和not "f"
。
无论输入如何,这都将是真实的答案。
答案 1 :(得分:0)
回答 Else Not working in "If Then Else" in VBA EXCEL
您需要类似的东西
Sub SpecificFlatArrears03()
Dim Flat As Variant
Do
Flat = InputBox("Pl Enter a Flat Number as 3 Digit without Prefix")
'at this point you should check that Flat meets the required requirements
Range("h3").Value = Flat
If (Flat > 100 And Flat < 165) Or (Flat > 200 And Flat < 264) Or (Flat > 300 And Flat < 364) Or Flat = 403 Or Flat = 404 Or Flat = 462 Or Flat = 463 Then
Range("h4") = WorksheetFunction.Match(Flat, Range("'2020-2021'!d11:d206"), 0)
Exit Do
End If
Loop Until False
End Sub