michaelsmith559
Well-known Member
- Joined
- Oct 6, 2013
- Messages
- 878
- Office Version
- 2013
- 2007
I would like to modify the following code so that it only lists combinations that fall between a certain range. I am trying to add an if then statement but have not been able to get it to work. Does anyone know how to add a line or lines of code so that I can make this list only combinations that fall between: 5280.111 and 5280.537? Also, if the combinations fill up the column how can I make it continue to the next column or as many columns as needed? Thanks for any help. Here is the code:
Sub Combinations()
Dim i As Long, j As Long, k As Long, l As Long, m As Long, n As Long
Dim CountComb As Long, lastrow As Long
Range("I2").Value = Now
Application.ScreenUpdating = False
CountComb = 0: lastrow = 2
For i = 1 To 32: For j = 1 To 40
For k = 1 To 47: For l = 1 To 44
For m = 1 To 38: For n = 1 To 34
Range("K" & lastrow).Value = Range("A" & i).Value & "," & _
Range("B" & j).Value & "," & _
Range("C" & k).Value & "," & _
Range("D" & l).Value & "," & _
Range("E" & m).Value & "," & _
Range("F" & n).Value
lastrow = lastrow + 1
CountComb = CountComb + 1
Next: Next
Next: Next
Next: Next
Range("I1").Value = CountComb
Range("I3").Value = Now
Application.ScreenUpdating = True
End Sub
Sub Combinations()
Dim i As Long, j As Long, k As Long, l As Long, m As Long, n As Long
Dim CountComb As Long, lastrow As Long
Range("I2").Value = Now
Application.ScreenUpdating = False
CountComb = 0: lastrow = 2
For i = 1 To 32: For j = 1 To 40
For k = 1 To 47: For l = 1 To 44
For m = 1 To 38: For n = 1 To 34
Range("K" & lastrow).Value = Range("A" & i).Value & "," & _
Range("B" & j).Value & "," & _
Range("C" & k).Value & "," & _
Range("D" & l).Value & "," & _
Range("E" & m).Value & "," & _
Range("F" & n).Value
lastrow = lastrow + 1
CountComb = CountComb + 1
Next: Next
Next: Next
Next: Next
Range("I1").Value = CountComb
Range("I3").Value = Now
Application.ScreenUpdating = True
End Sub