永发信息网

excel如何用宏代码向数组输入符合条件的数据

答案:2  悬赏:10  手机版
解决时间 2021-02-19 03:07
  • 提问者网友:且恨且铭记
  • 2021-02-18 06:57
在工作薄中列有数据,想创建数组用来存放指定数据(a),我这么写,报错。
Sub aa()
Dim i As Long
Dim n As Long
Dim arr() As String
For Each sht In Sheets
For i = 1 To 100
If sht.Cells(i, 1).Value = "a" Then
arr(n) = sht.Cells(i, 1).Value
n = n + 1
End If
Next i
Next
End Sub
好像是数组定义出错,怎么改!谢谢先
最佳答案
  • 五星知识达人网友:北方的南先生
  • 2021-02-18 07:05
试试:
 Sub aa()
  Dim i As Long
  Dim n As Long
  Dim arr() As String
  For Each sht In Sheets
      For i = 1 To 100
          If sht.Cells(i, 1).Value = "a" Then
             n = n + 1
             ReDim Preserve arr(n)
             arr(n) = sht.Cells(i, 1).Value
          End If
      Next i
  Next
End Sub
全部回答
  • 1楼网友:猎心人
  • 2021-02-18 07:18

如图:

“d4”单元格公式为:

=mod((left(b4,1)+left(b3,1)),9)&right(b3,len(b3)-1)

将公式拖下去即可。

不知我是否弄明白了你的要求。

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯