![](/img/trans.png)
[英]Comparing version numbers with more than one decimal point in Excel VBA
[英]Comparing Decimal Values Excel VBA
百分比是用整數表示的十進制數。 例如,將100.00%存儲為1,將98.01%存儲為.9801。
因此,您需要調整閾值:
For Each i In WSData.Range("A7", WSData.Range("A7").End(xlDown)).Cells
If i.Offset(0, 3).Value >= .98 Then
i.EntireRow.Delete
End If
Next
第二個問題是,刪除行時最好向后迭代。 否則,它可能會丟失某些行,因為在刪除每一行時,它會被上移,然后下一次迭代將跳過下一行。
將i從一個范圍更改為一個很長的范圍,然后使用它:
For i = WSData.Range("A7").End(xlDown).row to 7 Step -1
If WSData.Cells(i,3).Value >= .98 Then
Row(i).Delete
End If
Next
編輯:因為它看起來像數字格式上有一個自定義掩碼,它迫使數字看起來像百分比,請嘗試以下操作:
For i = WSData.Range("A7").End(xlDown).row to 7 Step -1
If WSData.Cells(i,3).Value >= 98 Then
Row(i).Delete
End If
Next
如果這可行,那么您的主要問題是您正在查看D列。偏移量是累加的。 因此,當您使用.offset(0,3)
它從列A移動了三列。1 + 3為4。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.