Multiple columns into rows
Closed
ybtronic
Posts
1
Registration date
Thursday 17 June 2010
Status
Member
Last seen
17 June 2010
-
17 Jun 2010 à 18:05
rizvisa1 Posts 4478 Registration date Thursday 28 January 2010 Status Contributor Last seen 5 May 2022 - 17 Jun 2010 à 20:26
rizvisa1 Posts 4478 Registration date Thursday 28 January 2010 Status Contributor Last seen 5 May 2022 - 17 Jun 2010 à 20:26
Related:
- Multiple columns into rows
- Split excel sheet into multiple files - Guide
- How to delete rows and columns in word - Guide
- Excel drop down list multiple columns - Guide
- Tweetdeck larger columns - Guide
- Convert multiple rows to columns in excel macro - Guide
1 response
rizvisa1
Posts
4478
Registration date
Thursday 28 January 2010
Status
Contributor
Last seen
5 May 2022
766
17 Jun 2010 à 20:26
17 Jun 2010 à 20:26
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