title: Range method not selecting right line in VBA - Excel
body: <p>I've been strugling to color alternate rows in a range in VBA. The problem is that the Range method seems not to select the proper range and I end up coloring adjacent cells. This is my desired output:</p>
  
  <p><a href="https://i.stack.imgur.com/baKFw.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/baKFw.jpg" alt="desired output. Alternate rows colored by grey"></a></p>
  
  <p>But, this is what I actually get:</p>
  
  <p><a href="https://i.stack.imgur.com/g3dtv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/g3dtv.png" alt="enter image description here"></a></p>
  
  <p>This is the code I created:</p>
  
  <pre><code>Sub limpar_aniversariantes()
      Worksheets("Aniversariantes").Range("B4:D900").ClearContents
      'Worksheets("Aniversariantes").Range("B4:D900").Interior.Color = RGB(255, 255, 255)
  End Sub
  
  
  Sub gerar_lista_aniversariantes()
      limpar_aniversariantes
      Dim newrange As Range, rw As Range
      Sheets("Base de Alunos").Select
      Set newrange = ActiveSheet.AutoFilter.Range.SpecialCells(xlCellTypeVisible)
      CountInicioMes = 12
      CountInicio = 16
      Count = CountInicio
      count_first_line = 0
      For Each rw In newrange.Rows
          Worksheets("Aniversariantes").Range("B" &amp; Count).Value = rw.Cells(2).Value
          Worksheets("Aniversariantes").Range("C" &amp; Count).Value = Left(rw.Cells(5).Value, 2)
          Worksheets("Aniversariantes").Range("C" &amp; Count).NumberFormat = "DD"
          Worksheets("Aniversariantes").Range("D" &amp; Count).Value = UCase(rw.Cells(15).Value)
          'Worksheets("Aniversariantes").Range("A" &amp; Count).Value = Count
          'pintar linhas alternadamente de cinza
          If Count Mod 2 = 0 Then
              Worksheets("Aniversariantes").Range("B" &amp; Count &amp; ":D" &amp; Count).Interior.Color = RGB(211, 211, 211)
              Debug.Print ("B" &amp; Count &amp; ":D" &amp; Count)
          End If
          'pegar mes dos aniversariantes, eh preciso pular header
          If count_first_line &lt; 2 Then
              count_first_line = count_first_line + 1
              If count_first_line = 2 Then
                 my_date = rw.Cells(5).Value
              End If
          End If
          'Debug.Print Left(rw.Cells(5).Value, 2)
          Count = Count + 1
          'Debug.Print rw.Cells(2).Value
      Next rw
      Worksheets("Aniversariantes").Range("B" &amp; (CountInicio + 1) &amp; ":D" &amp; Count).Sort key1:=Worksheets("Aniversariantes").Range("C" &amp; (CountInicio + 1) &amp; ":C" &amp; Count), _
      Header:=xlNo
      'limpar bordas anteriores
      Worksheets("Aniversariantes").Columns("B:D").Borders.LineStyle = xlNone
      Worksheets("Aniversariantes").Range("B" &amp; (CountInicio) &amp; ":D" &amp; (Count - 1)).Borders.LineStyle = xlContinuous
      '.Weight = xlThin.ColorIndex = 3
      my_month = Mid(my_date, 4, 2)
      my_month_written = RetornarMes(CInt(my_month))
      Worksheets("Aniversariantes").Range("B" &amp; CountInicioMes).Value = UCase(my_month_written)
      Worksheets("Aniversariantes").Range("B" &amp; CountInicio).Value = "NOME"
      Worksheets("Aniversariantes").Range("C" &amp; CountInicio).Value = "DIA"
      Worksheets("Aniversariantes").Range("D" &amp; CountInicio).Value = "MODALIDADE"
      'mudar cor de fundo
      'Worksheets("Aniversariantes").Range("B" &amp; CountInicio &amp; ":D" &amp; CountInicio).Interior.Color = RGB(255, 255, 0)
      'Debug.Print my_month_written
  
  End Sub
  </code></pre>
  
  <p>I am coping values from one worksheet to another and I am using MOD function to only color even lines. Everytime I copy these values the number of lines can change, that's why I need to do it by VBA. I am not mastered in VBA so any help is appreciated. I have struggled to do it the whole morning.</p>
  
  <p>Edit: I notticed that choosing a row out of the PERSON's data table makes the Range().Interior.Color function works properly, the problem is inside the range.</p>