求助一段VBA代码(合并和相加,取奇偶数)
来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/11/11 11:49:59
求助一段VBA代码(合并和相加,取奇偶数)
要求:1、把F2和F3合并,(F1为标题),结果放在F2.如1和2,合并为12,同时删除F3内容.接着把F4和F5合并(同上)直至F列为空.
2、把I2和I3相加,(I1为标题),相加结果个位为奇数的,把奇字放在I2,(相加结果个位为偶数的,把偶字放在I2)同时删除I3内容,接着把I4和I5相加(同上)直至I列为空.
要求:1、把F2和F3合并,(F1为标题),结果放在F2.如1和2,合并为12,同时删除F3内容.接着把F4和F5合并(同上)直至F列为空.
2、把I2和I3相加,(I1为标题),相加结果个位为奇数的,把奇字放在I2,(相加结果个位为偶数的,把偶字放在I2)同时删除I3内容,接着把I4和I5相加(同上)直至I列为空.
Sub iTest()
Dim r&, rs&, rng As Range, arr
With ActiveSheet
rs = .Cells(65536, "F").End(xlUp).Row
If rs Mod 2 = 0 Then rs = rs + 1
With .Cells(2, "F").Resize(rs - 2 + 1)
arr = .Cells
.ClearContents
For r = LBound(arr) To UBound(arr) - 1 Step 2
arr(r, 1) = arr(r, 1) & arr(r + 1, 1)
arr(r + 1, 1) = ""
Next
.Cells = arr
End With
rs = .Cells(65536, "I").End(xlUp).Row
If rs Mod 2 = 0 Then rs = rs + 1
With .Cells(2, "I").Resize(rs - 2 + 1)
arr = .Cells
.ClearContents
For r = LBound(arr) To UBound(arr) - 1 Step 2
If (arr(r, 1) + arr(r + 1, 1)) Mod 2 = 0 Then
arr(r, 1) = "偶"
Else
arr(r, 1) = "奇"
End If
arr(r + 1, 1) = ""
Next
.Cells = arr
End With
End With
MsgBox "ok!"
End Su
Dim r&, rs&, rng As Range, arr
With ActiveSheet
rs = .Cells(65536, "F").End(xlUp).Row
If rs Mod 2 = 0 Then rs = rs + 1
With .Cells(2, "F").Resize(rs - 2 + 1)
arr = .Cells
.ClearContents
For r = LBound(arr) To UBound(arr) - 1 Step 2
arr(r, 1) = arr(r, 1) & arr(r + 1, 1)
arr(r + 1, 1) = ""
Next
.Cells = arr
End With
rs = .Cells(65536, "I").End(xlUp).Row
If rs Mod 2 = 0 Then rs = rs + 1
With .Cells(2, "I").Resize(rs - 2 + 1)
arr = .Cells
.ClearContents
For r = LBound(arr) To UBound(arr) - 1 Step 2
If (arr(r, 1) + arr(r + 1, 1)) Mod 2 = 0 Then
arr(r, 1) = "偶"
Else
arr(r, 1) = "奇"
End If
arr(r + 1, 1) = ""
Next
.Cells = arr
End With
End With
MsgBox "ok!"
End Su
求助一段matlab代码
word vba 取几个数中的最小值?
VBA程序设计代码,输入一个大于一的整数,然后分别计算从0到该数之间的奇数和和偶数和,怎么设计?如图
第二问对n取奇偶数的讨论*
pascal题:取数,求代码!
数6,-1,15,-3中,任取三个不同的数相加,其中和最小的是( )
有80个数,其中奇偶各一半,任取2个数,则所取的2数和为偶数的概率是?
经常有题目让你写通项公式中要分奇偶数写,但答案往往把奇偶两种情况合并在一个式子中写,要怎么才能合并呢?每次看半天都合并不
小学奥数题(等差数列和奇偶问题)
求奇偶数之和和差的公式或者求法
C语言编程:判断奇偶数并求奇数和
有五个数,每取两个数相加,得到十个和,再把这十个数相加,得到2064,原来五个数的和是多少