excel vba中的过程调用或参数无效

时间:2016-10-19 03:18:05

标签: excel vba excel-vba

我在sheet1的column1上使用过滤器,使用唯一的no,将来自Z列的过滤值转换为数组(arr)对象,并将这些值作为字符串粘贴到" Dashboard"片。对sheet1的第1列上的所有唯一值重复此过程。我收到多个错误1."无效的过程调用或参数"在Join()方法中。 2.将值获取到rng对象和数组中。我可以帮助我解决这个问题。非常感谢。

Dim d As Object, c As Range, k, tmp As String
Dim TestRg As Range
Dim arr() As Variant
Dim i As Integer
Dim myCell As Range
Dim rng As Range
i = 2

Set d = CreateObject("scripting.dictionary")
Columns(1).Select
For Each c In Selection
    tmp = Trim(c.Value)
    If Len(tmp) > 0 Then d(tmp) = d(tmp) + 1
Next c

For Each k In d.Keys
If IsNumeric(k) Then
 Set TestRg = Range("A1:AQ" & LastRow(ActiveSheet))
 TestRg.AutoFilter Field:=1, Criteria1:=k, Operator:=xlFilterValues
 LasRow = ActiveSheet.UsedRange.Rows(ActiveSheet.UsedRange.Rows.Count).Row
 Set rng = ActiveSheet.Range("Z1" & ":" & "Z" & LasRow).SpecialCells(xlCellTypeVisible)
 rng.Activate
 arr = rng.Value
Worksheets("Dashboard").Range("A" & i) = k
Worksheets("Dashboard").Range("E" & i).Resize(UBound(arr, 1)).Value = Join(arr, " ")
i = i + 1
Erase arr
End If
Next k

1 个答案:

答案 0 :(得分:0)

至于你的帖子要求帮助的错误,它来自:

Worksheets("Dashboard").Range("E" & i).Resize(UBound(arr, 1)).Value = Join(arr, " ")

因为arr 两个 -dimensional 数组,而Join()函数需要 一个 -dimensional 一个

那么你应该:

  • 将arr声明为简单变体:

    Dim arr As Variant
    
  • 以某种方式填充它以生成 One-dimensional 数组

    arr = Application.Transpose(rng.Value)
    

除此之外,在我看来你的代码还有一些问题

您可能希望先修复此错误然后,如果这些问题确实出现并且您无法修复,请发布新帖