title: Click button to increment/decrement a loop
body: <p><a href="https://i.stack.imgur.com/nHCe8.jpg" rel="nofollow noreferrer">To Explain What I need</a>   <a href="https://i.stack.imgur.com/8CPQc.jpg" rel="nofollow noreferrer">Input Parameters</a>    <a href="https://i.stack.imgur.com/056Qi.jpg" rel="nofollow noreferrer">User form</a></p>
  
  <p>I have defined the variables on my sheet.2 within text boxes, and on my VBA form (Sheet.1) I have a Plus command button and a Minus command Button, I want the loop to progress only when any of these buttons are clicked. </p>
  
  <p>'**** Function to determine Layer ID of the Sources and define their Elevation and Rotation Angle</p>
  
  <pre><code>Function LayerID()
  Sheet2.NumberOfSunPositionsBox.Enabled = False
  Sheet2.NumberOfSunPositionsBox.Enabled = False
  Sheet1.AngleOfRotationBox.Enabled = False
  Sheet1.AngleOfElevationBox.Enabled = False
  
  Dim RotationStep, MinRotation, MaxRotation, ElevatioStep, MinElevation, MaxElevation As Integer
  
  RotationStep = Sheet2.RotationStepBox
  MinRotation = Sheet2.MinRotationlAngleBox
  MaxRotation = Sheet2.MaxRotationAngleBox
  ElevationStep = Sheet2.ElevationStepBox
  MinElevation = Sheet2.MinElevationAngleBox
  MaxElevation = Sheet2.MaxElevationAngleBox
  
  NumberOfRotations = (MaxRotation - MinRotation) / RotationStep + 1
  NumberOfElevations = (MaxElevation - MinElevation) / ElevationStep + 1
  NumberOfSunPositions = NumberOfRotations * NumberOfElevations
      If MaxElevation = 90 Then
      NumberOfSunPositions = NumberOfSunPositions + 1
      End If
  
  Sheet2.NumberOfSunPositionsBox = NumberOfSunPositions
  Sheet1.AngleOfElevationBox = MinElevation
  Sheet1.AngleOfRotationBox = MinRotation
  'Power1 = 0
  'Power2 = 100
  
      For Elevation = MinElevation To MaxElevation Step ElevationStep
  '        If Sheet1.ElevationPlusButton Then
             If LayerNumber &lt;= NumberOfSunPositions Then
             Sheet1.ElevationPlusButton.Enabled = True
                      If Elevation = 90 Then
                      Rotation = 0
                      LayerNumber = LayerNumber + 1
                      Debug.Print ("Layer ID:" &amp; LayerNumber &amp; " E:" &amp; Elevation &amp; " R:" &amp; Rotation)
                      Sheet1.AngleOfElevationBox = Elevation
                      Else
                          For Rotation = MinRotation To MaxRotation Step RotationStep
  '                        If Sheet1.RotationPlusButton Then
  '                            Sheet1.RotationPlusButton.enable = True
                              LayerNumber = LayerNumber + 1
                              Debug.Print ("Layer ID:" &amp; LayerNumber &amp; " E:" &amp; Elevation &amp; " R:" &amp; Rotation)
                              Sheet1.AngleOfRotationBox = Rotation
  '                        End If
                          Next Rotation
                      End If
              End If
  '        End If
      Next Elevation
  End Function
  </code></pre>