VBA 数组下标越界
PrivateSubCommandButton1_Click()Sheets("2015").SelectDimxxx()xxx=Range("b2:f5")Range(...
Private Sub CommandButton1_Click()
Sheets("2015").Select
Dim xxx()
xxx = Range("b2:f5")
Range("v2:z5") = xxx
Dim d, dd()
Set d = CreateObject("scripting.dictionary")
Dim x, y As Variant
ReDim y(34) As Integer
ReDim x(5) As Integer
y = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35)
x = Array(4, 6, 8, 88, 99, 0)
'---------------------------------共几个相同数据
For i = 0 To UBound(y)
d(y(i)) = ""
Next
For i = 0 To UBound(x)
If d.exists(x(i)) Then a = a + 1
Next
MsgBox a
Set d = Nothing
'------------------------------------找出不同的数据
n = 1
K = 0
For i = LBound(y) To UBound(y)
For j = LBound(xxx) To UBound(xxx)
If xxx(j) = y(i) Then
K = 0
Exit For
Else
K = K + 1
If K = UBound(xxx) + 1 Then
ReDim Preserve dd(1 To n)
dd(n) = y(i)
n = n + 1
K = 0
End If
End If
Next
Next
MsgBox Join(dd, ",")
End Sub 展开
Sheets("2015").Select
Dim xxx()
xxx = Range("b2:f5")
Range("v2:z5") = xxx
Dim d, dd()
Set d = CreateObject("scripting.dictionary")
Dim x, y As Variant
ReDim y(34) As Integer
ReDim x(5) As Integer
y = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35)
x = Array(4, 6, 8, 88, 99, 0)
'---------------------------------共几个相同数据
For i = 0 To UBound(y)
d(y(i)) = ""
Next
For i = 0 To UBound(x)
If d.exists(x(i)) Then a = a + 1
Next
MsgBox a
Set d = Nothing
'------------------------------------找出不同的数据
n = 1
K = 0
For i = LBound(y) To UBound(y)
For j = LBound(xxx) To UBound(xxx)
If xxx(j) = y(i) Then
K = 0
Exit For
Else
K = K + 1
If K = UBound(xxx) + 1 Then
ReDim Preserve dd(1 To n)
dd(n) = y(i)
n = n + 1
K = 0
End If
End If
Next
Next
MsgBox Join(dd, ",")
End Sub 展开
展开全部
更多追问追答
追问
很好。。那么 如何将MsgBox Join(dd, ",")
结果输出到 Z列。并且代码比较的不全,代码好像有问题。得出24位数,这是不对的。有好多重复了。因为代码的目的是比较XXX数组和Y数组,输出Y数组中有,XXX没有的差值。不是重值。我追加分
追答
这个很难帮你,我们都不知道你要做什么。我们只能告诉你一些关于语法方面的错误。
至于你说的将Join(dd, ",")输出到Z列,那是件容易的事。
如果这个都不会,很难想像,你的那些代码又是怎么写出来的。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询