|
楼主 |
发表于 2023-2-23 13:10
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
这个是我用循环判断写的一个,感觉好慢,想用数组和字典,但是还不会。
和本案列有点相似。不是本案列的代码 用循环写的烦人的部分代码 实在是字数限制贴不上来
Set sheet = ThisWorkbook.Sheets("生产经营性收支")
For y = 3 To sheet.Cells(Rows.Count, 2).End(3).Row
If sheet.Cells(y, 6) = k(I) Then
Select Case sheet.Cells(y, 10)
Case "生产经营性支出":
If CByte(sheet.Cells(y, 9)) = 1 Then
sheet.Cells(y, "o") = sheet.Cells(y, "n")
s = s + sheet.Cells(y, "n")
ElseIf CByte(sheet.Cells(y, 9)) = 2 Then
sheet.Cells(y, "o") = sheet.Cells(y, "n")
t = t + sheet.Cells(y, "n")
ElseIf CByte(sheet.Cells(y, 9)) = 3 Then
sheet.Cells(y, "o") = sheet.Cells(y, "n")
m = m + sheet.Cells(y, "n")
ElseIf CByte(sheet.Cells(y, 9)) = 4 Then
sheet.Cells(y, "o") = sheet.Cells(y, "n")
n = n + sheet.Cells(y, "n")
End If
Case "生产经营性收入":
If sheet.Cells(y, 11) = "养殖业" Then
If CByte(sheet.Cells(y, 9)) = 1 Then
sheet.Cells(y, "o") = sheet.Cells(y, "n")
s1 = s1 + sheet.Cells(y, "n")
ElseIf CByte(sheet.Cells(y, 9)) = 2 Then
sheet.Cells(y, "o") = sheet.Cells(y, "n")
t1 = t1 + sheet.Cells(y, "n")
ElseIf CByte(sheet.Cells(y, 9)) = 3 Then
sheet.Cells(y, "o") = sheet.Cells(y, "n")
m1 = m1 + sheet.Cells(y, "n")
ElseIf CByte(sheet.Cells(y, 9)) = 4 Then
sheet.Cells(y, "o") = sheet.Cells(y, "n")
n1 = n1 + sheet.Cells(y, "n")
End If
ElseIf sheet.Cells(y, 11) = "种植业" Or sheet.Cells(y, 11) = "林果业" Or sheet.Cells(y, 11) = "林下" Then
If CByte(sheet.Cells(y, 9)) = 1 Then
sheet.Cells(y, "o") = sheet.Cells(y, "n")
s2 = s2 + sheet.Cells(y, "n")
ElseIf CByte(sheet.Cells(y, 9)) = 2 Then
sheet.Cells(y, "o") = sheet.Cells(y, "n")
t2 = t2 + sheet.Cells(y, "n")
ElseIf CByte(sheet.Cells(y, 9)) = 3 Then
sheet.Cells(y, "o") = sheet.Cells(y, "n")
m2 = m2 + sheet.Cells(y, "n")
ElseIf CByte(sheet.Cells(y, 9)) = 4 Then
sheet.Cells(y, "o") = sheet.Cells(y, "n")
n2 = n2 + sheet.Cells(y, "n")
End If
Else
If CByte(sheet.Cells(y, 9)) = 1 Then
sheet.Cells(y, "o") = sheet.Cells(y, "n")
s3 = s3 + sheet.Cells(y, "n")
ElseIf CByte(sheet.Cells(y, 9)) = 2 Then
sheet.Cells(y, "o") = sheet.Cells(y, "n")
t3 = t3 + sheet.Cells(y, "n")
ElseIf CByte(sheet.Cells(y, 9)) = 3 Then
sheet.Cells(y, "o") = sheet.Cells(y, "n")
m3 = m3 + sheet.Cells(y, "n")
ElseIf CByte(sheet.Cells(y, 9)) = 4 Then
sheet.Cells(y, "o") = sheet.Cells(y, "n")
n3 = n3 + sheet.Cells(y, "n")
End If
End If
End Select
End If
Next y
sht.Cells(6, "t") = s ' (一)生产经营性支出
sht.Cells(9, "t") = t ' (一)生产经营性支出
sht.Cells(12, "t") = m ' (一)生产经营性支出
sht.Cells(15, "t") = n ' (一生产经营性支出
sht.Cells(6, "e") = s2 ' (一)种植收入
sht.Cells(9, "e") = t2 ' (一)
sht.Cells(12, "e") = m2 ' (一))
sht.Cells(15, "e") = n2 ' (一生
sht.Cells(6, "f") = s1 ' (一)养殖收入
sht.Cells(9, "f") = t1 ' (一)
sht.Cells(12, "f") = m1 ' (一)
sht.Cells(15, "f") = n1 ' (一
sht.Cells(6, "g") = s3 ' (一)其他
sht.Cells(9, "g") = t3 ' (一)
sht.Cells(12, "g") = m3 ' (一)
sht.Cells(15, "g") = n3 ' (一)
s = 0
t = 0
m = 0
n = 0
s1 = 0
t1 = 0
m1 = 0
n1 = 0
s2 = 0
t2 = 0
m2 = 0
n2 = 0
s3 = 0
t3 = 0
m3 = 0
n3 = 0
End If
Next
|
|