我有下面的代码,用于合并/合并1-4列中具有相同文本的所有重复行,并对第5列中的值求和。
代码已经正常运行了一段时间,但是突然突然停止工作,并且我遇到了以下错误消息:
编译错误:
声明无效的外部类型块
任何帮助解决此问题的方法将不胜感激
Sub nSum()
Dim Rng As Range, Dn As Range, n As Long, Txt As String, Ac As Long
Set Rng = Range(Range("A1"), Range("A" & Rows.Count).End(xlUp))
ray(1 To Rng.Count, 1 To 4) 'Column count ''***ERROR LINE***************
With CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
For Each Dn In Rng
Txt = Join(Application.Transpose(Application.Transpose(Dn.Resize(, 3))), ",")
If Not .Exists(Txt) Then
n = n + 1
For Ac = 1 To 4: ray(n, Ac) = Dn.Offset(, Ac - 1): Next Ac
.Add Txt, n
Else
ray(.Item(Txt), 4) = ray(.Item(Txt), 4) + Dn.Offset(, 3)
End If
Next
n = .Count
End With
With Sheets("Sheet2").Range("A1").Resize(n, 4)
.Value = ray
.Borders.Weight = 2
.Columns.AutoFit
End With
End Sub'
答案 0 :(得分:2)
我猜您正在尝试声明或重新初始化名为ray
的数组。
因此,单词ReDim
或Dim
被跳过了:
Sub nSum()
Dim Rng As Range, Dn As Range, n As Long, Txt As String, Ac As Long
Set Rng = Range(Range("A1"), Range("A" & Rows.Count).End(xlUp))
Dim ray(1 To Rng.Count, 1 To 4) 'Or Redim Ray(1 To ...
'Rest of the code
End Sub