Macro to convert rows to columns

Riaang

Board Regular
Joined
Aug 29, 2002
Messages
146
Hi there,

Can anyone help me to write a macro that can convert rows into columns. I have a excel spreadsheet and in column A is the member number. From B to E will be the rest of the detail. On the second line or row the member number will repeat in column A but in column B to E is different information for the member than in row 1.

I want all the information of the member to be in one line. Some member have only 2 lines whereby other members can have more than that.

Any help will be appreciated.

Thanks
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
I tried using the Macro that Half ace wrote and it works to some degree to naturalize the data. But when I try it on a fresh spreadsheet (unaltered) that is emailed to me it comes up with a error 400. Here is how the fields of the data are. Help is much appreciated.

The goal is to get all four rows (one record) into one row : Plan - Forecast - Actual - Comments.
Report.xls
ABCDEFGHIJKLMNOPQRSTUV
1Record NameCASPR Project No., Search Ring Name, Site TypeProject TypeMarketPlan/ Forecast/ Actual DatesMS000 Handoff to CPMMS010 Search Ring IssuedMS020 Primary ApprovedMS030 Lease Fully ExecutedMS036 Zoning SubmittedMS040 Zoning ApprovedMS075 BP SubmittedMS080 BP ReceivedMS093 Site Acq. CompleteMS095 Construction StartMS110 Site Ready For Equip.MS120 Equip. Install CompleteMS125 Construction CompleteMS145 RF Opt. & Integrated (private)MS150 Site Opt. & Integration (on air)MS155 Turnover Package Comp. (BLIP)MS160 Final Acceptance
2A-04-008 - Voorheesville WTA-04-008 - Voorheesville WTNewNew YorkPlan2/4/20042/4/20042/17/20043/4/20042/24/20043/25/20043/1/20043/11/20044/26/20045/1/20045/6/20045/7/20045/11/20048/25/20045/20/20047/21/2004
3A-04-008 - Voorheesville WTA-04-008BuildForecast2/10/20042/10/20047/12/200410/15/200411/19/20045/14/20055/14/20055/27/20053/20/20055/2/20055/29/20056/6/20056/6/20058/25/20046/20/20056/22/2005
4A-04-008 - Voorheesville WTColoActual2/4/20042/4/20047/19/200410/15/200411/12/2004
5A-04-008 - Voorheesville WTComments: Existing tank, ground space available for monopole
Report
 
Upvote 0
Do you need what shown below?
Cartel1
ABCDEFGHIJKLMN
1RecordNameData1Data2Data3Data4
2AIYOUHESHE
3AWEYOUTHEY
4AREDGREEN
5
6Doyouwantwhatbelow??
7
81
9RecordNameData1Data2Data3Data4Data1Data2Data3Data4Data1Data2Data3Data4
10AIYOUHESHEWEYOUTHEYREDGREEN
11
Foglio1
 
Upvote 0
Book1
ABCD
1RecordNameA-04-008-VoorheesvilleWTA-04-008-VoorheesvilleWTA-04-008-VoorheesvilleWT
2CASPRProjectNo.,SearchRingName,SiteTypeA-04-008-VoorheesvilleWTA-04-008Colo
3ProjectTypeNewBuild
4MarketNewYork
5Plan/Forecast/ActualDatesPlanForecastActual
6MS000HandofftoCPM2/4/20042/10/20042/4/2004
7MS010SearchRingIssued2/4/20042/10/20042/4/2004
Sheet2

Is the above what you would like the data to look like? If not, could you post an example of what you would like your data to look like when you're done?
 
Upvote 0
For each record (those four rows) it should be rearranged to look like this.

The records can be as small as 1000 rows or as many as.... ???

HalfAce's original macro would be a good starting point because it normalizes the data, buit the end result is the following (mock data).

This is one record, so their would be many more of these repeating.

Every four rows of above example would become the following.
Book1
ABCDEF
2Record NameMarketMStitle1PlanActualForecast
3Record NameMarketMStitle21/1/20041/1/20041/1/2004
4Record NameMarketMStitle31/2/20041/2/20041/2/2004
5Record NameMarketMStitle41/3/20041/3/20041/3/2004
6Record NameMarketMStitle51/4/20041/4/20041/4/2004
7Record NameMarketMStitle61/5/20041/5/20041/5/2004
8Record NameMarketMStitle71/6/20041/6/20041/6/2004
9Record NameMarketMStitle81/7/20041/7/20041/7/2004
10Record NameMarketMStitle91/8/20041/8/20041/8/2004
Sheet1
 
Upvote 0
OK I've cleaned up my examples.
I've been playing around withit all weekend and I'm lost -- I'm not very good at excel based macros (obviously) :oops:



This is orignal spreadsheet sent to me where each record is in this format:.
CingularProjectCycleReport8.xls
ABCDEFGHIJKLMNOPQRSTUV
5RecordNameProjectNo.,Name,SiteTypeProjectTypeMarketPlan/Forecast/ActualDatesMS000HandofftoCPMMS010SearchRingIssuedMS020PrimaryApprovedMS030LeaseFullyExecutedMS036ZoningSubmittedMS040ZoningApprovedMS075BPSubmittedMS080BPReceivedMS093SiteAcq.CompleteMS095ConstructionStartMS110SiteReadyForEquip.MS120Equip.InstallCompleteMS125ConstructionCompleteMS145RFOpt.&Integrated(private)MS150SiteOpt.&Integration(onair)MS155TurnoverPackageComp.(BLIP)MS160FinalAcceptance
6Record1Record1NewNewYorkPlan10/9/200310/9/200310/22/200311/7/200310/29/200311/28/200311/4/200311/14/200312/30/2003
7Record16156BuildForecast10/9/200310/9/200312/1/20037/8/20043/2/20044/23/20047/21/20048/31/20049/1/2004
8Record1NoneActual10/9/200310/9/200312/1/20037/8/20043/2/20044/23/20047/30/20048/31/20049/1/2004
9BerryRidgeComments:Dual
DummyData
 
Upvote 0
Ciao,
I'm interested in helping you, but for this I need further information. Can you post columns from A to D of 2 or 3 records in the original spreadsheet.
I understand that each original record is made by 4 rows: Column A of fourth row has different information ("Berry Ridge" vs Record1) and Column B starts with "Comment".

... Wait for response.... :ROFLMAO: :ROFLMAO:
 
Upvote 0
I renamed the projects inthe previous example for clarity. Here is an extract of the first 3 records.

Please note that C (c6:c8) and D (d6:d8) are merged.
C8.xls
ABCDEFGHIJKLMNOPQRSTUV
5RecordNameProjectNo.,SearchRingName,SiteTypeProjectTypeMarketPlan/Forecast/ActualDatesMS000HandofftoCPMMS010SearchRingIssuedMS020PrimaryApprovedMS030LeaseFullyExecutedMS036ZoningSubmittedMS040ZoningApprovedMS075BPSubmittedMS080BPReceivedMS093SiteAcq.CompleteMS095ConstructionStartMS110SiteReadyForEquip.MS120Equip.InstallCompleteMS125ConstructionCompleteMS145RFOpt.&Integrated(private)MS150SiteOpt.&Integration(onair)MS155TurnoverPackageComp.(BLIP)MS160FinalAcceptance
6BerryRidgeBerryRidgeNewGeorgiaPlan10/9/200310/9/200310/22/200311/7/200310/29/200311/28/200311/4/200311/14/200312/30/2003
7BerryRidge6156BuildForecast10/9/200310/9/200312/1/20037/8/20043/2/20044/23/20047/21/20048/31/20049/1/2004
8BerryRidgeCondoActual10/9/200310/9/200312/1/20037/8/20043/2/20044/23/20047/30/20048/31/20049/1/2004
9BerryRidgeComments:
10
11BridgemillBridgemillNewGeorgiaPlan10/3/200310/3/200310/16/200311/1/200310/23/200311/22/200310/29/200311/8/200312/24/200312/29/20031/3/20041/4/20041/8/20044/1/20041/17/20045/28/2004
12Bridgemill6157BuildForecast10/3/200310/3/200310/30/200312/12/20031/28/20042/11/20042/12/20042/25/20041/20/20042/26/20043/1/20043/12/20043/12/20044/1/20049/29/20049/30/2004
13BridgemillCondoActual10/3/200310/3/200310/30/200312/12/20031/28/20042/11/20042/12/20042/25/20041/20/20042/26/20043/1/20043/12/20043/12/20044/1/20049/29/20049/30/2004
14BridgemillComments:
15
16N.AycockStN.AycockStNewGeorgiaPlan10/3/200310/3/200310/16/200311/1/200310/23/200311/22/200310/29/200311/8/200312/24/200312/29/20031/3/20041/4/20041/8/20045/28/20041/17/20049/21/2004
17N.AycockSt6159BuildForecast10/3/200310/3/200312/3/20032/13/20043/3/20043/12/20043/8/20043/15/20043/12/20044/5/20044/13/20045/26/20044/20/20045/28/20049/14/20049/21/2004
18N.AycockStCondoActual10/3/200310/3/200312/3/20032/13/20043/3/20043/12/20043/8/20043/15/20043/12/20044/5/20044/13/20045/26/20044/20/20045/28/20049/14/20049/21/2004
19N.AycockStComments:
20
C8
 
Upvote 0
I have finished (hours of work) a code which should suit your request (teste on data you provided).

Post for feedback :p :ROFLMAO:

Hypthesis: Source data in Sheet(1)
Destination in Sheet(2)

Code:

Sub Macro6()
'
' Macro6 Macro
' Macro registrata il 24/01/2005 da FSC
'

'
Dim Sheet1LastRow As Long, Sheet2RowPointer As Long, PointerIncr As Long
Dim AllRange As Range, OneCopyRange As Range
Dim CELLi As Range, RangeToCopy As Range
Dim CopyColFrom As Long, CopyColTo As Long
Dim StrMarking As String

Application.ScreenUpdating = False

'Sheets 2 cleaning
Sheets(2).Cells.Delete

On Error Resume Next
Sheets(1).ShowAllData
On Error GoTo 0

'Last row index acquisition
Sheet1LastRow = Sheets(1).Cells(Cells.Rows.Count, 1).End(xlUp).Row
'Initialization of Pointer to first blank row in Sheet 2
Sheet2RowPointer = 1

'Set Columns Number to copy
CopyColFrom = 5 'First
CopyColTo = Sheets(1).Range("A1").End(xlToRight).Column 'Last

'Data range acquisition
Set AllRange = Sheets(1).Range(Sheets(1).Range("A1"), Sheets(1).Cells(Sheet1LastRow, CopyColTo))

'Acquisition of all different records
AllRange.Columns(1).AdvancedFilter Action:=xlFilterInPlace, Unique:=True
Set OneCopyRange = AllRange.Columns(1).SpecialCells(xlCellTypeVisible)

'Momently clear column A cells relevant to Comments
For PointerIncr = 5 To Sheet1LastRow Step 5
Sheets(1).Cells(PointerIncr, 1).ClearContents
Next PointerIncr

'Setting of PointerIncr to be used after the copy procedure
PointerIncr = CopyColTo - CopyColFrom + 1

'Filter all different records
AllRange.AutoFilter
For Each CELLi In OneCopyRange
Sheets(1).Activate
'Skip A1 and empty cells
If CELLi.Row <> 1 And Trim(CELLi) <> "" Then
AllRange.AutoFilter Field:=1, Criteria1:=CELLi

'Acquisition of Marking String Data
StrMarking = AllRange.Columns(4).SpecialCells(xlCellTypeVisible).Cells(2, 1)

'Range to copy acquisition
Set RangeToCopy = _
Range(AllRange.Columns(CopyColFrom), AllRange.Columns(CopyColTo)).SpecialCells(xlCellTypeVisible)

'Copy data
RangeToCopy.Copy
Sheets(2).Activate
Sheets(2).Cells(Sheet2RowPointer, 3).PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=True
Sheets(1).Range("A1").Copy Destination:=Sheets(2).Cells(Sheet2RowPointer, 1)
Sheets(1).Range("A2").Copy
Sheets(2).Range(Cells(Sheet2RowPointer + 1, 1), Cells(Sheet2RowPointer + PointerIncr - 1, 2)).PasteSpecial _
Paste:=xlPasteFormats, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Sheets(2).Range(Cells(Sheet2RowPointer + 1, 1), Cells(Sheet2RowPointer + PointerIncr - 1, 1)) = CELLi
Sheets(1).Range("D1").Copy Destination:=Sheets(2).Cells(Sheet2RowPointer, 2)
Sheets(2).Range(Cells(Sheet2RowPointer + 1, 2), Cells(Sheet2RowPointer + PointerIncr - 1, 2)) = StrMarking
'Increment of the pointer for next copy
Sheet2RowPointer = PointerIncr + Sheet2RowPointer
End If
Next CELLi

'Columns Width Adjustment (Autofit)
With Sheets(2).Columns("A:F")
.ColumnWidth = 100
.AutoFit
.Rows.AutoFit
End With

Sheets(1).Activate
'Clear Filter
Sheets(1).ShowAllData
'Restore column A cells relevant to Comments
For PointerIncr = 5 To Sheet1LastRow Step 5
Sheets(1).Cells(PointerIncr, 1) = Sheets(1).Cells(PointerIncr - 1, 1)
Next PointerIncr
Sheets(2).Activate
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,323
Members
449,077
Latest member
jmsotelo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top