Multiple columns into rows
Closed
ybtronic
Posts
1
Registration date
Thursday June 17, 2010
Status
Member
Last seen
June 17, 2010
-
Jun 17, 2010 at 06:05 PM
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 - Jun 17, 2010 at 08:26 PM
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 - Jun 17, 2010 at 08:26 PM
Related:
- Multiple columns into rows
- Allow multiple downloads chrome - Guide
- How to delete multiple files on mac - Guide
- Photoshop multiple selections - Guide
- Display two columns in data validation list but return only one - Guide
- How to delete rows and columns in word - Guide
1 response
rizvisa1
Posts
4478
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
May 5, 2022
766
Jun 17, 2010 at 08:26 PM
Jun 17, 2010 at 08:26 PM
Try this
It is assuming that
the two sheets are called sheet1 and sheet2
sheet2 headers are already set
data is to be copied from sheet1 to sheet2
Sub ShiftAround()
Dim Cell As Range
Dim lSheet1Row As Long
Dim lSheet2Row As Long
Dim lRow As Long
Dim iCol As Integer
Set Cell = Cells.Find("*", Cells(1, 1), SearchOrder:=xlByRows, SearchDirection:=xlPrevious)
If Cell Is Nothing Then Exit Sub
lSheet1Row = Cell.Row
For lRow = 1 To lSheet1Row
Sheets("Sheet1").Select
' CHECK IF THE ROW IS ODD
If (lRow Mod 2 = 1) Then
sValue = Cells(lRow, "B")
'CHECK IF THE ROW IS NOT NULL (BY DEFAUL MUST BE ALSO EVEN)
ElseIf (Cells(lRow, "A") <> "") Then
iCol = Cells(lRow, Columns.Count).End(xlToLeft).Column
Range(Cells(lRow, 2), Cells(lRow, iCol)).Copy
Sheets("Sheet2").Select
lSheet2Row = Cells(Rows.Count, "A").End(xlUp).Row
lSheet2Row = lSheet2Row + 1
Range("B" & lSheet2Row).PasteSpecial Transpose:=True
Range("A" & lSheet2Row & ":A" & Cells(Rows.Count, "B").End(xlUp).Row).Value = sValue
End If
Next lRow
Set Cell = Nothing
End Sub
It is assuming that
the two sheets are called sheet1 and sheet2
sheet2 headers are already set
data is to be copied from sheet1 to sheet2
Sub ShiftAround()
Dim Cell As Range
Dim lSheet1Row As Long
Dim lSheet2Row As Long
Dim lRow As Long
Dim iCol As Integer
Set Cell = Cells.Find("*", Cells(1, 1), SearchOrder:=xlByRows, SearchDirection:=xlPrevious)
If Cell Is Nothing Then Exit Sub
lSheet1Row = Cell.Row
For lRow = 1 To lSheet1Row
Sheets("Sheet1").Select
' CHECK IF THE ROW IS ODD
If (lRow Mod 2 = 1) Then
sValue = Cells(lRow, "B")
'CHECK IF THE ROW IS NOT NULL (BY DEFAUL MUST BE ALSO EVEN)
ElseIf (Cells(lRow, "A") <> "") Then
iCol = Cells(lRow, Columns.Count).End(xlToLeft).Column
Range(Cells(lRow, 2), Cells(lRow, iCol)).Copy
Sheets("Sheet2").Select
lSheet2Row = Cells(Rows.Count, "A").End(xlUp).Row
lSheet2Row = lSheet2Row + 1
Range("B" & lSheet2Row).PasteSpecial Transpose:=True
Range("A" & lSheet2Row & ":A" & Cells(Rows.Count, "B").End(xlUp).Row).Value = sValue
End If
Next lRow
Set Cell = Nothing
End Sub