title: Copy Rows into columns using VBA
body: <p>I have a very little experience with VBA, and I would really appreciate any help with this issue. 
  I need to convert rows into columns from sheet 1 to sheet 2.</p>
  
  <p>Input File </p>
  
  <p><a href="https://i.stack.imgur.com/4Vs6h.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4Vs6h.png" alt="Input File"></a></p>
  
  <p>Desired Output </p>
  
  <p><a href="https://i.stack.imgur.com/J96fN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/J96fN.png" alt="Desired Output"></a></p>
  
  <p>Sample data </p>
  
  <p><a href="https://i.stack.imgur.com/q2ooG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/q2ooG.png" alt="Sample data"></a></p>
  
  <p>My Code </p>
  
  <pre><code>Sub TransposeSpecial()
  
      Dim lMaxRows As Long 'max rows in the sheet
      Dim lThisRow As Long 'row being processed
      Dim iMaxCol As Integer 'max used column in the row being processed
  
      lMaxRows = Cells(Rows.Count, "A").End(xlUp).Row
  
      lThisRow = 2 'start from row 2
  
      Do While lThisRow &lt;= lMaxRows
  
          iMaxCol = Cells(lThisRow, Columns.Count).End(xlToLeft).Column
  
          If (iMaxCol &gt; 1) Then
              Rows(lThisRow + 1 &amp; ":" &amp; lThisRow + iMaxCol - 1).Insert
              Range(Cells(lThisRow, 2), Cells(lThisRow, iMaxCol)).Copy
              Range("C" &amp; lThisRow + 1).Select
              Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:=False, Transpose:=True
              Range(Cells(lThisRow, 2), Cells(lThisRow, iMaxCol)).Clear
              lThisRow = lThisRow + iMaxCol - 1
              lMaxRows = Cells(Rows.Count, "A").End(xlUp).Row
          End If
  
          lThisRow = lThisRow + 1
      Loop
  End Sub
  </code></pre>
  
  <p>Output obtained by Code </p>
  
  <p><a href="https://i.stack.imgur.com/BIkqZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BIkqZ.png" alt="Output obtained by Code"></a></p>
  
  <p>Desired output </p>
  
  <p><a href="https://i.stack.imgur.com/BOyVS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BOyVS.png" alt="Desired output"></a></p>