0

我有一个函数Sub fRemoveCharList(ColArray As Variant, char As Variant)(下面的代码)来删除一个字符列表 wrt 一个标题名称列表。

如果我打电话给...

Sub RemoveCharList()

  fRemoveCharList Array("field1","field2","field3"), Array("]", "&", "%")
End Sub

...它工作正常

但如果我去...

Call fRemoveCharList(("field1","field2","field3"), ("]","&","%"))

...这是我的首选方式,我收到“类型不匹配”错误。我需要有一个数组数组才能像这样使用它吗?

我已经用谷歌搜索了如何继续,但没有找到我可以使用的东西。

功能:

Sub fRemoveCharList(ColArray As Variant, char As Variant)

Dim x As Variant
Dim LR As Long, i As Long, j As Long
Dim Heading As Variant
Dim headingFound As Range
Dim lngColIndex As Long

For Each Heading In ColArray
    On Error Resume Next
    Set headingFound = Range("1:1").Find(What:=Heading, LookIn:=xlFormulas, LookAt:=xlPart)
    Err.Clear: On Error GoTo 0: On Error GoTo -1
    If Not headingFound Is Nothing Then lngColIndex = headingFound.Column

  LR = Cells(Rows.Count, lngColIndex).End(xlUp).Row

  For i = 1 To LR
      With Cells(i, lngColIndex)
          x = .Value
          For j = LBound(char) To UBound(char)
              x = Replace(x, char(j), vbNullString)
          Next
          .Value = x
      End With
    Next i
  Next
End Sub
4

1 回答 1

1

尝试以下任一:

Run fRemoveCharList Array("field1","field2","field3"), Array("]", "&", "%")

或者:

Call fRemoveCharList(Array("field1","field2","field3"), Array("]","&","%"))
于 2013-09-30T18:50:41.853 回答