Solved

Excel 2010 - split one row into 2 rows and offset

Posted on 2013-05-22
3
716 Views
Last Modified: 2013-05-23
I would like either vba code or a macro to split the attached spreadsheet as follows:

A1:V1 - Remain as titles
A2:V2 - Remain in row 2
Insert new row and move W2:AK2 to this row as follows
W2 would become F3, X2 would become G3 and so on

Carry on for the remaining 244 rows
Book1.xlsx
0
Comment
Question by:andymacf
  • 2
3 Comments
 
LVL 26

Accepted Solution

by:
redmondb earned 500 total points
ID: 39188289
Hi, andymacf.

Please see attached. Couple of points...
(1) I changed the contents of columns A and W for testing purposes.
(2) It's not the fastest code, but it's OK for a few hundred rows. Let me know if you are planning to run this against tens of thousands.

The code is...
Option Explicit

Sub Split_Rows()
Dim i As Long
Dim xLast_Row As Long

ThisWorkbook.Sheets("Sheet1").Activate

xLast_Row = ActiveSheet.UsedRange.Cells(1, 1).Row + ActiveSheet.UsedRange.Rows.Count - 1
If xLast_Row < 2 Then
    MsgBox ("No data found - run cancelled.")
    Exit Sub
End If

Application.ScreenUpdating = False
    
    For i = xLast_Row To 2 Step -1
    
        Rows(i + 1).Insert Shift:=xlShiftDown
    
        Range("W" & i & ":AK" & i).Cut Destination:=Range("F" & i + 1 & ":T" & i + 1)
    
    Next
    
Columns("W:AK").Delete Shift:=xlToLeft

Application.ScreenUpdating = True

MsgBox "Run complete - " & xLast_Row - 1 & " rows processed."

End Sub

Open in new window

Thanks,
Brian.Book1b-V2.xlsm
0
 
LVL 7

Author Closing Comment

by:andymacf
ID: 39190140
Fantastic job, this file will only ever be run against the 245 rows so it is a perfect fit.
Thanks Brian, much appreciated.
0
 
LVL 26

Expert Comment

by:redmondb
ID: 39190485
Thanks, andymacf, glad to help.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Embed scroll excel chart and data in powerpoint 9 78
Need Help with Mapping ONLY 9 26
Preserve formatting during mail merge using VBA 18 43
Excel Macro 9 22
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

830 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