【发布时间】:2014-06-18 14:57:40
【问题描述】:
我正在寻找一种方法来简化我的代码。如果可能的话,也许使用数组?任何帮助将不胜感激。
Cells.Replace What:="Invoice EMEA Payment", Replacement:="Invoice", LookAt:=xlWhole
On Error Resume Next
Cells.Replace What:="Invoice EMEA No Payment", Replacement:="Invoice", LookAt:=xlWhole
On Error Resume Next
Cells.Replace What:="Invoice USA Payment", Replacement:="Invoice", LookAt:=xlWhole
On Error Resume Next
Cells.Replace What:="Invoice USA No Payment", Replacement:="Invoice", LookAt:=xlWhole
On Error Resume Next
Cells.Replace What:="Invoice1 Lite EMEA Payment", Replacement:="Invoice1 Lite", LookAt:=xlWhole
On Error Resume Next
Cells.Replace What:="Invoice1 Lite EMEA No Payment", Replacement:="Invoice1 Lite", LookAt:=xlWhole
On Error Resume Next
Cells.Replace What:="Invoice1 Lite USA Payment", Replacement:="Invoice1 Lite", LookAt:=xlWhole
On Error Resume Next
Cells.Replace What:="Invoice1 Lite USA No Payment", Replacement:="Invoice1 Lite", LookAt:=xlWhole
On Error Resume Next
【问题讨论】:
-
您可以将这些完善的字符串包装在一个
string数组中,该数组存储在一个全局类型的 sub 中,然后对其进行迭代......将这种可重复和可重用的信息存储在全局sub 可以节省大量时间。