title: Make a loop VBA Excel
body: <p>I am new in the blog and I have some trouble with a loop.</p>
  
  <p>I did the next code to generate a random value (Range C4) and keep adding until 100 is reached.</p>
  
  <p>The code works fine but I want to make it in a loop.</p>
  
  <p>Also, There are 3 conditions:
  1) If range C6 have a 1 the variable "valor" wil be + 5
  2) If range D6 have a 1 the variable "valor" will be - 1
  3) If range C6 and range D6 both sum 2: first C6 will get 5 and the total sum will be -1</p>
  
  <p>Is there a way to make it using loop as well? or maybe case if?</p>
  
  <p>Thank you so much with the help!</p>
  
  <p>Cheers
  Hector</p>
  
  <pre><code>Sub Crashers()
  
  valor = Range("d4").Value 'acumulado
  
  '=========================== VALUES =============================
  If valor &lt; 100 Then
  
  Randomize
  Range("c4").Value = Int(20 * Rnd) + 1 'a = random
  
  If Range("c6") = 1 Then
  valor = valor + (Range("c4").Value + 5)
  Range("c6").Value = 0
  Range("d4").Value = valor
  
  Else
  
  If Range("d6") = 1 Then
  valor = (valor - 1) + Range("c4").Value
  Range("d6").Value = 0
  Range("d4").Value = valor
  Else
  
  
  If (Range("c6") + Range("d6")) = 0 Then
  valor = valor + Range("c4").Value
  Range("d4").Value = valor
  Else
  
  End If
  End If
  End If
  
  '   MsgBox "Maximo es " &amp; valor
  '=========================== VALUES =============================
  Else
      Range("C4:D4").Select
      Selection.ClearContents
      Range("C4").Select
  
      Range("d4").Value = 0
      Range("c4").Value = 0
  
  End If
  End Sub
  </code></pre>