title: Combining a loop and an if statement
body: <p>I have 2 sheets. 
  Sheet 1 contains the data I want to copy.
  If you can provide me with a hint on how to approach, I should be able to code the rest on my own. </p>
  
  <p>My logic was to create a loop, that would select all cells if a condition is met. This condition would be,
  if cell(i,1) = cell(i+1,1)</p>
  
  <p>I have attached 2 photos, the first is on how the original data in sheet 1 looks, and the second is sheet 2 with how the data looks after transformation.
  <img src="https://i.stack.imgur.com/vk7TG.png" alt="image 1">
  <img src="https://i.stack.imgur.com/pgR0V.png" alt="Image 2 "></p>
  
  <p>Here is my code where I get an error (Next without For)</p>
  
  <pre><code>Sub Loop_if()
  
  Dim ws As Worksheet
  Set ws = ws("sheet2")
  
  Dim i As Integer
  i = 2
  For i = 2 To 23000
  
      If Cells(i, 1) = Cells(i + 1, 1) Then
      Range(Cells(i, 3), Cells(i, 25)).Select
      Selection.Copy
      ws.Select
      If ws.Cells(i, 1) = Cells(i, 1) Then
      Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
      False, Transpose:=True
  
  
  End If
  Next i
  </code></pre>
  
  <p>End Sub</p>