title: VBA exit before end
body: <p>The code: a commandutton code with two parts, The first part of it sort the cells, and second part is recoloring the sorted cells.</p>
  
  <p>The problem: the macro exit after the first, without doing the recoloring. If I commented the first part, the code does the recoloring.</p>
  
  <p>Any idea, what could be the problem?</p>
  
  <pre><code>Private Sub CommandButton1_Click()
  Application.ScreenUpdating = False
  
  Dim i As Integer
  Dim WName As String
  
  
  ''First Part
  WName = ActiveWorkbook.ActiveSheet.Name
  Range("B2:B21").Select
  ActiveWorkbook.Worksheets(WName).Sort.SortFields.Clear
  ActiveWorkbook.Worksheets(WName).Sort.SortFields.Add Key:=Range("B2:B21"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
  With ActiveWorkbook.Worksheets(WName).Sort
      .SetRange Range("B2:B21")
      .Header = xlGuess
      .MatchCase = False
      .Orientation = xlTopToBottom
      .SortMethod = xlPinYin
      .Apply
  End With
  
  
  ''Second Part
  For i = 2 To 21
      If i Mod 2 = 0 Then
          Cells(i, 2).Select
          With Selection.Interior
              .Pattern = xlSolid
              .PatternColorIndex = xlAutomatic
              .ThemeColor = xlThemeColorAccent3
              .TintAndShade = 0.799981688894314
              .PatternTintAndShade = 0
          End With
      Else
          Cells(i, 2).Select
          With Selection.Interior
              .Pattern = xlSolid
              .PatternColorIndex = xlAutomatic
              .ThemeColor = xlThemeColorAccent3
              .TintAndShade = 0.399975585192419
              .PatternTintAndShade = 0
          End With
      End If
  Next i
  
  End Sub
  </code></pre>