关于循环求和在一个范围内的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