All, I completed the below Excel VBA code and it successfully works. However I know it’s incredibly inefficient. Can one of you VBA Gurus please show me a simplified way of writing the below loop code?
Thanks in Advance</SPAN>
Sub loops()
x = 1
Dim ZERO As Integer
Dim ONE As Integer '0100
Dim TWO As Integer '0200
Dim THREE As Integer '0300
Dim FOUR As Integer '0400
Dim FIVE As Integer '0500
Dim SIX As Integer '0600
Dim SEVEN As Integer '0700
Dim EIGHT As Integer '0800
Dim NINE As Integer '0900
Dim TEN As Integer '1000
Dim ELEVEN As Integer '1100
Dim TWELVE As Integer '1200
Dim THIRTEEN As Integer '1300
Dim FOURTEEN As Integer '1400
Dim FIFTEEN As Integer '1500
Dim SIXTEEN As Integer '1600
Dim SEVENTEEN As Integer '1700
Dim EIGHTTEEN As Integer '1800
Dim NINETEEN As Integer '1900
Dim TWENTY As Integer '2000
Dim TWENTYONE As Integer '2100
Dim TWENTYTWO As Integer '2200
Dim TWENTYTHREE As Integer '2300
Dim TWENTYFOUR As Integer '2400
Do While Cells(x, 2).Value <> ""
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value = 0 And Cells(x, 3).Value >= 0) Then ZERO = ZERO + 1
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value <= 1 And Cells(x, 3).Value >= 1) Then ONE = ONE + 1
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value <= 2 And Cells(x, 3).Value >= 2) Then TWO = TWO + 1
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value <= 3 And Cells(x, 3).Value >= 3) Then THREE = THREE + 1
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value <= 4 And Cells(x, 3).Value >= 4) Then FOUR = FOUR + 1
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value <= 5 And Cells(x, 3).Value >= 5) Then FIVE = FIVE + 1
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value <= 6 And Cells(x, 3).Value >= 6) Then SIX = SIX + 1
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value <= 7 And Cells(x, 3).Value >= 7) Then SEVEN = SEVEN + 1
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value <= 8 And Cells(x, 3).Value >= 8) Then EIGHT = EIGHT + 1
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value <= 9 And Cells(x, 3).Value >= 9) Then NINE = NINE + 1
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value <= 10 And Cells(x, 3).Value >= 10) Then TEN = TEN + 1
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value <= 11 And Cells(x, 3).Value >= 11) Then ELEVEN = ELEVEN + 1
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value <= 12 And Cells(x, 3).Value >= 12) Then TWELVE = TWELVE + 1
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value <= 13 And Cells(x, 3).Value >= 13) Then THIRTEEN = THIRTEEN + 1
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value <= 14 And Cells(x, 3).Value >= 14) Then FOURTEEN = FOURTEEN + 1
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value <= 15 And Cells(x, 3).Value >= 15) Then FIFTEEN = FIFTEEN + 1
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value <= 16 And Cells(x, 3).Value >= 16) Then SIXTEEN = SIXTEEN + 1
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value <= 17 And Cells(x, 3).Value >= 17) Then SEVENTEEN = SEVENTEEN + 1
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value <= 18 And Cells(x, 3).Value >= 18) Then EIGHTTEEN = EIGHTTEEN + 1
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value <= 19 And Cells(x, 3).Value >= 19) Then NINETEEN = NINETEEN + 1
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value <= 20 And Cells(x, 3).Value >= 20) Then TWENTY = TWENTY + 1
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value <= 21 And Cells(x, 3).Value >= 21) Then TWENTYONE = TWENTYONE + 1
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value <= 22 And Cells(x, 3).Value >= 22) Then TWENTYTWO = TWENTYTWO + 1
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value <= 23 And Cells(x, 3).Value >= 23) Then TWENTYTHREE = TWENTYTHREE + 1
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value <= 24 And Cells(x, 3).Value >= 24) Then TWENTYFOUR = TWENTYFOUR + 1
x = x + 1
Loop
Cells(1, 8).Value = ZERO
Cells(2, 8).Value = ONE
Cells(3, 8).Value = TWO
Cells(4, 8).Value = THREE
Cells(5, 8).Value = FOUR
Cells(6, 8).Value = FIVE
Cells(7, 8).Value = SIX
Cells(8, 8).Value = SEVEN
Cells(9, 8).Value = EIGHT
Cells(10, 8).Value = NINE
Cells(11, 8).Value = TEN
Cells(12, 8).Value = ELEVEN
Cells(13, 8).Value = TWELVE
Cells(14, 8).Value = THIRTEEN
Cells(15, 8).Value = FOURTEEN
Cells(16, 8).Value = FIFTEEN
Cells(17, 8).Value = SIXTEEN
Cells(18, 8).Value = SEVENTEEN
Cells(19, 8).Value = EIGHTTEEN
Cells(20, 8).Value = NINETEEN
Cells(21, 8).Value = TWENTY
Cells(22, 8).Value = TWENTYONE
Cells(23, 8).Value = TWENTYTWO
Cells(24, 8).Value = TWENTYTHREE
Cells(25, 8).Value = TWENTYFOUR
End Sub
Thanks in Advance</SPAN>
Sub loops()
x = 1
Dim ZERO As Integer
Dim ONE As Integer '0100
Dim TWO As Integer '0200
Dim THREE As Integer '0300
Dim FOUR As Integer '0400
Dim FIVE As Integer '0500
Dim SIX As Integer '0600
Dim SEVEN As Integer '0700
Dim EIGHT As Integer '0800
Dim NINE As Integer '0900
Dim TEN As Integer '1000
Dim ELEVEN As Integer '1100
Dim TWELVE As Integer '1200
Dim THIRTEEN As Integer '1300
Dim FOURTEEN As Integer '1400
Dim FIFTEEN As Integer '1500
Dim SIXTEEN As Integer '1600
Dim SEVENTEEN As Integer '1700
Dim EIGHTTEEN As Integer '1800
Dim NINETEEN As Integer '1900
Dim TWENTY As Integer '2000
Dim TWENTYONE As Integer '2100
Dim TWENTYTWO As Integer '2200
Dim TWENTYTHREE As Integer '2300
Dim TWENTYFOUR As Integer '2400
Do While Cells(x, 2).Value <> ""
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value = 0 And Cells(x, 3).Value >= 0) Then ZERO = ZERO + 1
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value <= 1 And Cells(x, 3).Value >= 1) Then ONE = ONE + 1
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value <= 2 And Cells(x, 3).Value >= 2) Then TWO = TWO + 1
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value <= 3 And Cells(x, 3).Value >= 3) Then THREE = THREE + 1
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value <= 4 And Cells(x, 3).Value >= 4) Then FOUR = FOUR + 1
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value <= 5 And Cells(x, 3).Value >= 5) Then FIVE = FIVE + 1
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value <= 6 And Cells(x, 3).Value >= 6) Then SIX = SIX + 1
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value <= 7 And Cells(x, 3).Value >= 7) Then SEVEN = SEVEN + 1
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value <= 8 And Cells(x, 3).Value >= 8) Then EIGHT = EIGHT + 1
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value <= 9 And Cells(x, 3).Value >= 9) Then NINE = NINE + 1
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value <= 10 And Cells(x, 3).Value >= 10) Then TEN = TEN + 1
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value <= 11 And Cells(x, 3).Value >= 11) Then ELEVEN = ELEVEN + 1
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value <= 12 And Cells(x, 3).Value >= 12) Then TWELVE = TWELVE + 1
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value <= 13 And Cells(x, 3).Value >= 13) Then THIRTEEN = THIRTEEN + 1
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value <= 14 And Cells(x, 3).Value >= 14) Then FOURTEEN = FOURTEEN + 1
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value <= 15 And Cells(x, 3).Value >= 15) Then FIFTEEN = FIFTEEN + 1
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value <= 16 And Cells(x, 3).Value >= 16) Then SIXTEEN = SIXTEEN + 1
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value <= 17 And Cells(x, 3).Value >= 17) Then SEVENTEEN = SEVENTEEN + 1
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value <= 18 And Cells(x, 3).Value >= 18) Then EIGHTTEEN = EIGHTTEEN + 1
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value <= 19 And Cells(x, 3).Value >= 19) Then NINETEEN = NINETEEN + 1
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value <= 20 And Cells(x, 3).Value >= 20) Then TWENTY = TWENTY + 1
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value <= 21 And Cells(x, 3).Value >= 21) Then TWENTYONE = TWENTYONE + 1
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value <= 22 And Cells(x, 3).Value >= 22) Then TWENTYTWO = TWENTYTWO + 1
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value <= 23 And Cells(x, 3).Value >= 23) Then TWENTYTHREE = TWENTYTHREE + 1
If Cells(x, 1).Value Like "*NMC*" And (Cells(x, 2).Value <= 24 And Cells(x, 3).Value >= 24) Then TWENTYFOUR = TWENTYFOUR + 1
x = x + 1
Loop
Cells(1, 8).Value = ZERO
Cells(2, 8).Value = ONE
Cells(3, 8).Value = TWO
Cells(4, 8).Value = THREE
Cells(5, 8).Value = FOUR
Cells(6, 8).Value = FIVE
Cells(7, 8).Value = SIX
Cells(8, 8).Value = SEVEN
Cells(9, 8).Value = EIGHT
Cells(10, 8).Value = NINE
Cells(11, 8).Value = TEN
Cells(12, 8).Value = ELEVEN
Cells(13, 8).Value = TWELVE
Cells(14, 8).Value = THIRTEEN
Cells(15, 8).Value = FOURTEEN
Cells(16, 8).Value = FIFTEEN
Cells(17, 8).Value = SIXTEEN
Cells(18, 8).Value = SEVENTEEN
Cells(19, 8).Value = EIGHTTEEN
Cells(20, 8).Value = NINETEEN
Cells(21, 8).Value = TWENTY
Cells(22, 8).Value = TWENTYONE
Cells(23, 8).Value = TWENTYTWO
Cells(24, 8).Value = TWENTYTHREE
Cells(25, 8).Value = TWENTYFOUR
End Sub