乔山办公网我们一直在努力
您的位置:乔山办公网 > excel表格制作 > <em>excel</em> <em>数组</em> <em>

<em>excel</em> <em>数组</em> <em>

作者:乔山办公网日期:

返回目录:excel表格制作


Const N = 10
Sub main()
Dim a, i%, k%, m%
a = Array(-3, 4, 7, 9, 13, 45, 67, 89, 100, 180)
k = -1
Debug.Print "a数组中的如下:"
For i = 0 To N - 1
Debug.Print a(i);
Next
Debug.Print
m = InputBox("Enter m:")
For i = 0 To N - 1
If m = a(i) Then
k = i
Exit For
End If
Next
If (k >= 0) Then
Debug.Print "m="; m; "index="; k
Else
Debug.Print " not be found!"
End If
End Sub


=SUMPRODUCT((G$2:G$7=A2)*(H$2:H$7=B2)*I$2:I$7)
并设置0值不显示。

更多精彩,尽在Excel疑难千寻千解,欢迎到我的百度文库下载。

1、获取当前列的最大行数

2、通过循环,获取当前列的每个单元格的值

3、比较单元格的值是否在数组中

示例:

Sub a2()
   Dim cnt As Integer  '定义当前列行总数
   Dim tmp As String  '定义临时变量
   Dim i As Integer, j As Integer  '定义临时变量
   Dim a(2) As String '定义要查找的数组
   cnt = Range("A1").End(xlDown).Rows.Count '获取某一个列,这里是A列的行总数
   For i = 1 To cnt
      tmp = Range("A" + CStr(i)).Value  '获取当前列某个单元格的值
      For j = LBound(a) To UBound(a)   '数组中比较
          If tmp = a(j) Then  '当前单元格的值是否在数组中
              Debug.Print tmp '是的话就打印信息
          End If
      Next j
   Next i
End Sub


那只有用循环来做!
双重循环
Option Explicit

Private Sub Command1_Click()
Dim A, B
Dim C() As String
Dim i As Integer
Dim j As Integer
Dim n As Integer

A = Array("A", "B", "C", "D")
B = Array("A", "B")

'采用循环嵌套进行查核
n = -1
For i = 1 To UBound(A)
For j = 1 To UBound(B)
If A(i) = B(j) Then Exit For
Next j
If j > UBound(B) Then
n = n + 1
ReDim Preserve C(n) As String
C(n) = A(i)
End If
Next i
'输出数组C
If n > -1 Then
For i = 0 To UBound(C)
Print C(i)
Next i
Else
Print "数组C没有元素!"
End If
End Sub

相关阅读

  • -excel 数组连接,excel数组函数

  • 乔山办公网excel表格制作
  • ALT+F11,把下列百代码输入进度去。Function conall(cll As Variant)Dim cl As VariantFor Each cl In cll conall = conall & clNext clEnd Function然后回到问工答作表输入版公式:=conall
关键词不能为空
极力推荐

ppt怎么做_excel表格制作_office365_word文档_365办公网