Solved

VBA Excel script to add columns and convert to single row per item.

Posted on 2014-03-03
2
455 Views
Last Modified: 2014-03-04
Hello Experts

I'm looking for a script that will convert a spreadsheet from 2 rows per item to 1 row per item.

In order to preserve the flow of the data, I would like to insert a new column after each column from C to Y, rather than moving all the data in the 2nd row as a single block.

Contents of fields are mix of data and formulas.  Number of rows is 5000.

Thanks!
ee-script.xls
0
Comment
Question by:tomfolinsbee
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 39

Accepted Solution

by:
nutsch earned 500 total points
ID: 39903810
With the requirement of keeping the formula, it makes it hard to do batch processing. You can try the attached macro, but I expect it to be slow.

Sub Macro6()
Dim lLastRow As Long, lRowLoop As Long, lColLoop As Long

'turn off updates to speed up code execution
With Application
    .ScreenUpdating = False
    .EnableEvents = False
    .Calculation = xlCalculationManual
    .DisplayAlerts = False
End With

lLastRow = Cells(Rows.Count, 1).End(xlUp).Row

For lColLoop = 25 To 4 Step -1
    Columns(lColLoop).Insert
Next lColLoop

For lRowLoop = lLastRow To 4 Step -2
    For lColLoop = 3 To 48 Step 2
        Cells(lRowLoop, lColLoop).Cut Cells(lRowLoop - 1, lColLoop + 1)
    Next lColLoop
    
    Rows(lRowLoop).Delete
Next lRowLoop

With Application
    .ScreenUpdating = True
    .EnableEvents = True
    .Calculation = xlCalculationAutomatic
    .DisplayAlerts = True
End With


End Sub

Open in new window


Thomas
0
 

Author Closing Comment

by:tomfolinsbee
ID: 39905389
Thank you. Worked perfectly first time.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question