VBA问题,两个数组A(1,1 To 1,5)和B(1,1 To 1,5)要求比较他们包含的元素是否相同.

学习 时间:2026-04-02 20:38:20 阅读:6945
VBA问题,两个数组A(1,1 To 1,5)和B(1,1 To 1,5)要求比较他们包含的元素是否相同.比方说A数组包含1、2、10、7、4,B数组包含1、2、4、7、10则他们是相同的.

最佳回答

凶狠的星月

执着的御姐

2026-04-02 20:38:20

Sub test() a1 = Array(1, 2, 10, 7, 4) a2 = Array(1, 2, 7, 4, 10) tempArray1 = a1 tempArray2 = a2 For i = 0 To 4 For j = 0 To 4 If tempArray1(i) "" And tempArray2(j) "" Then If tempArray1(i) = tempArray2(j) Then tempArray1(i) = "" tempArray2(j) = "" End If End If Next j Next i For i = 0 To 4 If tempArray1(i) "" Or tempArray2(i) "" Then Count = Count + 1 End If Next i If Count = 0 Then MsgBox "the two arrays are the same" Else MsgBox "the two arrays are different" End IfEnd Su

最新回答共有2条回答

  • 光亮的战斗机
    回复
    2026-04-02 20:38:20

    Sub test() a1 = Array(1, 2, 10, 7, 4) a2 = Array(1, 2, 7, 4, 10) tempArray1 = a1 tempArray2 = a2 For i = 0 To 4 For j = 0 To 4 If tempArray1(i) "" And tempArray2(j) "" Then If tempArray1(i) = tempArray2(j) Then tempArray1(i) = "" tempArray2(j) = "" End If End If Next j Next i For i = 0 To 4 If tempArray1(i) "" Or tempArray2(i) "" Then Count = Count + 1 End If Next i If Count = 0 Then MsgBox "the two arrays are the same" Else MsgBox "the two arrays are different" End IfEnd Su

上一篇 ()然若失 ()然自得 ()然悔悟 ()然失色 ()然而至

下一篇 广加会是什么字?半包围结构.