EXCEL VBA 代码的问题?
C9是AQ9:AT9数值的除3余0的个数;D9是AQ9:AT9数值的除3余1的个数;E9是AQ9:AT9数值的除3余2的个数;一行一行相对应的;请老师帮忙,写个快速返回的...
C9是AQ9:AT9数值的除3余0的个数;
D9是AQ9:AT9数值的除3余1的个数;
E9是AQ9:AT9数值的除3余2的个数;
一行一行相对应的;
请老师帮忙,写个快速返回的数组代码,让这些余数值返回在图中的位置. 展开
D9是AQ9:AT9数值的除3余1的个数;
E9是AQ9:AT9数值的除3余2的个数;
一行一行相对应的;
请老师帮忙,写个快速返回的数组代码,让这些余数值返回在图中的位置. 展开
1个回答
展开全部
这个简单,好写,。。。
没注意,要数组!!!!~~~~,修改如下
Sub cm()
Dim r, i, j%
Dim a, b, c%
Dim arr, brr, sh1
Set sh1 = ActiveSheet
With sh1
r = .Range("at" & Rows.Count).End(xlUp).Row
.Range("c9:e" & Rows.Count).ClearContents
arr = .Range("aq9:at" & r)
ReDim brr(1 To UBound(arr), 1 To 3)
For i = 9 To r
a = 0
b = 0
c = 0
For j = 43 To 46
If .Cells(i, j) Mod 3 = 0 Then
a = a + 1
ElseIf .Cells(i, j) Mod 3 = 1 Then
b = b + 1
Else
c = c + 1
End If
brr(i - 8, 1) = a
brr(i - 8, 2) = b
brr(i - 8, 3) = c
Next j
Next i
.Range("c9").Resize(UBound(arr), 3) = brr
End With
End Sub
更多追问追答
追问
辛苦老师了,这一条 类型不匹配 啊
If .Cells(i, j) Mod 3 = 0 Then
追答
是不是有文本,具体要看到文档才能判断,如果时文本原因,修改如下
Sub cm()
Dim r, i, j%
Dim a, b, c%
Dim arr, brr, sh1
Set sh1 = ActiveSheet
With sh1
r = .Range("at" & Rows.Count).End(xlUp).Row
.Range("c9:e" & Rows.Count).ClearContents
arr = .Range("aq9:at" & r)
ReDim brr(1 To UBound(arr), 1 To 3)
For i = 9 To r
a = 0
b = 0
c = 0
For j = 43 To 46
If IsNumeric(.Cells(i, j)) Then
If .Cells(i, j) Mod 3 = 0 Then
a = a + 1
ElseIf .Cells(i, j) Mod 3 = 1 Then
b = b + 1
Else
c = c + 1
End If
brr(i - 8, 1) = a
brr(i - 8, 2) = b
brr(i - 8, 3) = c
End If
Next j
Next i
.Range("c9").Resize(UBound(arr), 3) = brr
End With
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询