EXCEL VBA 如何判断奇数和偶数列并分别求值 (求助高手)
答案:2 悬赏:20 手机版
解决时间 2021-11-18 16:16
- 提问者网友:献世佛
- 2021-11-18 08:30
EXCEL VBA 如何判断奇数和偶数列并分别求值 (求助高手)
最佳答案
- 五星知识达人网友:往事隔山水
- 2021-11-18 09:32
Sub tt()
Dim i, j, k1%, k2%, y
For i = 1 To 255
y = Cells(Rows.Count, i).End(xlUp).Row
If y = 1 Then GoTo 10
For j = y To y - 3 Step -1
If Cells(j, i) Mod 2 = 0 Then
k1 = 1
Else
k2 = 1
End If
Next j
If k1 = 1 And k2 = 1 Then
Cells(y + 2, i) = "NG"
ElseIf k1 = 1 And k2 = 0 Then
Cells(y + 2, i) = "0"
Else
Cells(y + 2, i) = "1"
End If
k1 = 0: k2 = 0
10:
Next i
End Sub追问If Cells(j, i) Mod 2 = 0 Then
哪里的是K列,哪里指的是O列
如果我从K列开始到AL列结束
怎么修改代码?追答只要改 for i=11 to 38 即可从K列到AL列,K就是11,AL就是38追问ok
Dim i, j, k1%, k2%, y
For i = 1 To 255
y = Cells(Rows.Count, i).End(xlUp).Row
If y = 1 Then GoTo 10
For j = y To y - 3 Step -1
If Cells(j, i) Mod 2 = 0 Then
k1 = 1
Else
k2 = 1
End If
Next j
If k1 = 1 And k2 = 1 Then
Cells(y + 2, i) = "NG"
ElseIf k1 = 1 And k2 = 0 Then
Cells(y + 2, i) = "0"
Else
Cells(y + 2, i) = "1"
End If
k1 = 0: k2 = 0
10:
Next i
End Sub追问If Cells(j, i) Mod 2 = 0 Then
哪里的是K列,哪里指的是O列
如果我从K列开始到AL列结束
怎么修改代码?追答只要改 for i=11 to 38 即可从K列到AL列,K就是11,AL就是38追问ok
全部回答
- 1楼网友:几近狂妄
- 2021-11-18 10:53
SUB 李大侠83()
DIM X,Y
A=[K8].CURRENTREGION
REDIM B(1 TO 1,1 TO UBOUND(A,2))
FOR X=1 TO UBOUND(A,2)
C=0:CC=0
FOR Y=UBOUND(A) TO UBOUND(A)-3 STEP -1
C=C+A(Y,X) MOD 2
CC=CC+1
NEXT
IF C=CC THEN
B(1,X)=1
ELSEIF C=0 THEN
B(1,X)=0
ELSE
B(1,X)="NG"
END IF
NEXT
[K13].RESIZE(,UBOUND(A,2))=B
END SUB追问c = c + a(Y, X) Mod 2追答测试了吗?追问测试了
运行不了
c = c + a(Y, X) Mod 2
提示
DIM X,Y
A=[K8].CURRENTREGION
REDIM B(1 TO 1,1 TO UBOUND(A,2))
FOR X=1 TO UBOUND(A,2)
C=0:CC=0
FOR Y=UBOUND(A) TO UBOUND(A)-3 STEP -1
C=C+A(Y,X) MOD 2
CC=CC+1
NEXT
IF C=CC THEN
B(1,X)=1
ELSEIF C=0 THEN
B(1,X)=0
ELSE
B(1,X)="NG"
END IF
NEXT
[K13].RESIZE(,UBOUND(A,2))=B
END SUB追问c = c + a(Y, X) Mod 2追答测试了吗?追问测试了
运行不了
c = c + a(Y, X) Mod 2
提示
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯