[英]MS word 2016 Macro
I am new to VBA but I have a word 2016 template and it has the following sections: 我是VBA的新手,但我有一个Word 2016模板,它包含以下部分:
Base Amount: $
Service Fee: $
Sales Tax % $
Other tax %: $
Tax 2 %: $
My goal is if an amount is missing from any of the lines, then delete that line. 我的目标是,如果任何行中都缺少金额,请删除该行。
I tried recording the macro and then making changes but no luck. 我尝试记录宏,然后进行更改,但没有运气。
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
I've added : 我已经添加 :
Trim
to remove useless spaces, so that you'll only have data left Trim
函数删除无用的空格,这样您只剩下数据 =
to <=
将=
更改为<=
Code : 代码:
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.