[英]MS word 2016 Macro
我是VBA的新手,但我有一個Word 2016模板,它包含以下部分:
Base Amount: $
Service Fee: $
Sales Tax % $
Other tax %: $
Tax 2 %: $
我的目標是,如果任何行中都缺少金額,請刪除該行。
我嘗試記錄宏,然后進行更改,但沒有運氣。
Sub TEST()
Dim i As Long
With Selection.Tables(1)
For i = .Rows.Count To 1 Step -1
If Len(.Cell(i, 2).Range.Text) = 2 Then
.Rows(i).Delete
End If
Next i
End With
End Sub
我已經添加 :
Trim
函數刪除無用的空格,這樣您只剩下數據 =
更改為<=
代碼:
Sub TEST()
Dim i As Integer
With Selection.Tables(1)
For i = .Rows.Count To 1 Step -1
If Len(Trim(.Cell(i, 2).Range.Text)) <= 2 Then
.Rows(i).Delete
End If
Next i
End With 'Selection.Tables(1)
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.