标题:关于循环求和在一个范围内的bug
只看楼主
tanbm
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2021-6-3
结帖率:0
已结贴  问题点数:20 回复次数:1 
关于循环求和在一个范围内的bug
各位大佬,我是一个萌新,
我写了这个代码,目的是:当sum在dyg1和dyg2范围内的时候,才生成值在表格内,但是现在他所有值都生成在表格

不知道哪里写错了,他不执行筛选

Sub 排列()
Dim b, c, d, e, f, g, ssum, dex, dyg1, dyg2, t As String
Dim sum As Long
dyg1 = Sheet1.[b11]
dyg2 = Sheet1.[b12]

Worksheets("sheet3").UsedRange.ClearContents
Worksheets("sheet4").UsedRange.ClearContents
a1 = Application.CountA(Sheet1.Range("b1:b10"))
a2 = Application.CountA(Sheet1.Range("d1:d60000"))
a3 = Application.CountA(Sheet1.Range("f1:f60000"))
a4 = Application.CountA(Sheet2.Range("b1:b60000"))
a5 = Application.CountA(Sheet2.Range("d1:d60000"))
a6 = Application.CountA(Sheet1.Range("l1:l60000"))

Index = 1
dex = 1

For columnB = 1 To a1
b = Worksheets("Sheet1").Cells(columnB, 2).Value

For columnC = 1 To a2
c = Worksheets("Sheet1").Cells(columnC, 4).Value

For columnD = 1 To a3
d = Worksheets("Sheet1").Cells(columnD, 6).Value

For columnE = 1 To a4
e = Worksheets("Sheet2").Cells(columnE, 2).Value

For columnF = 1 To a5
f = Worksheets("Sheet2").Cells(columnF, 4).Value

For columnG = 1 To a6
g = Worksheets("Sheet1").Cells(columnG, 12).Value

sum = b + c + d + e + f + g
ssum = b & "+" & c & "+" & d & "+" & e & "+" & f & "+" & g
If dyg1 <= sum <= dyg2 Then
Sheet3.Cells(Index, dex) = ssum & "——————" & sum

Index = Index + 1
End If

Next
Next
Next
Next
Next
Next

End Sub
搜索更多相关主题的帖子: For Application sum Next Value 
2021-06-03 22:06
sdta
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:江苏省连云港市
等 级:版主
威 望:323
帖 子:9621
专家分:26174
注 册:2012-2-5
得分:20 
试试:
a1 = Application.WorksheetFunction.CountA(Sheet1.Range("b1:b10"))

坚守VFP最后的阵地
2021-06-09 21:18



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-505939-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.053462 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved