+ Reply to Thread
Results 1 to 7 of 7

Format 1 row in excel to many rows incrementally by range in row until blank cell

Hybrid View

  1. #1
    Registered User
    Join Date
    05-26-2017
    Location
    Detroit, MI
    MS-Off Ver
    2010
    Posts
    3

    Format 1 row in excel to many rows incrementally by range in row until blank cell

    I would Like to format the following with an excel macro from Sheet1 (input) to sheet 2 (output)

    Sheet 1
    Capture.PNG

    Sheet 2 - Output from Sheet 1 Macro
    Capture1.PNG

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,698

    Re: Format 1 row in excel to many rows incrementally by range in row until blank cell

    Here is a Normalization Macro I developed awhile ago. It should get you on the right path and you may have to modify it to meet your specific needs as this was developed with only one static column (column A).

    Option Explicit
    
    
    Sub Normalize()
        Dim s1 As Worksheet, s2 As Worksheet
        Dim i As Long, lr As Long, lrt As Long
        Dim lc As Long
        Set s1 = Sheets("Sheet1")
        Set s2 = Sheets("Sheet2")
        lr = s1.Range("A" & Rows.Count).End(xlUp).Row
        Application.ScreenUpdating = False
    
        For i = 1 To lr
            lrt = s2.Range("B" & Rows.Count).End(xlUp).Row + 1
            lc = s1.Cells(i, Columns.Count).End(xlToLeft).Column
            s1.Range("A" & i).Copy s2.Range("A" & lrt)
            s1.Range(Cells(i, 2), Cells(i, lc)).Copy
            s2.Range("B" & lrt).PasteSpecial xlPasteValues, , , True
            Application.CutCopyMode = False
        Next i
    
        lrt = s2.Range("B" & Rows.Count).End(xlUp).Row
        For i = 3 To lrt
            If s2.Range("A" & i) = "" Then
                s2.Range("A" & i) = s2.Range("A" & i - 1)
            End If
        Next i
    
        Application.ScreenUpdating = True
    
    End Sub
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,957

    Re: Format 1 row in excel to many rows incrementally by range in row until blank cell

    Hi jmoore3535

    Welcome to the forum. Can give this a go...
    Option Explicit
    Sub MoveMe()
    Dim lRow As Long, nRow As Long, lCol As Long, _
    r As Long, c As Long
    Application.ScreenUpdating = False
    lRow = Sheet1.Cells(Rows.Count, "A").End(xlUp).Row
    nRow = Sheet2.Cells(Rows.Count, "A").End(xlUp).Row
    With Sheet1
        For r = 1 To lRow
            lCol = .Cells(r, .Columns.Count).End(xlToLeft).Column
                For c = 3 To lCol
                    If .Cells(r, c) > "" Then
                        Range(.Cells(r, 1), .Cells(r, 2)).Copy Destination:=Sheet2.Cells(nRow, 1)
                        Sheet2.Cells(nRow, 3) = .Cells(r, c)
                        nRow = nRow + 1
                    End If
                Next c
        Next r
    End With
    Application.ScreenUpdating = True
    End Sub
    Attached Files Attached Files
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  4. #4
    Registered User
    Join Date
    05-26-2017
    Location
    Detroit, MI
    MS-Off Ver
    2010
    Posts
    3

    Re: Format 1 row in excel to many rows incrementally by range in row until blank cell

    Thank you!! This worked perfectly!

    Both sintek and jindon's solution worked

    Thanks so much!

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Format 1 row in excel to many rows incrementally by range in row until blank cell

    Sub test()
        Dim a, b, i As Long, ii As Long, n As Long
        a = Cells(1).CurrentRegion.Value
        ReDim b(1 To UBound(a, 1) * UBound(a, 2), 1 To 3)
        For i = 1 To UBound(a, 1)
            For ii = 3 To UBound(a, 2)
                If a(i, ii) <> "" Then
                    n = n + 1: b(n, 1) = a(i, 1)
                    b(n, 2) = a(i, 2): b(n, 3) = a(i, ii)
                End If
        Next ii, i
        Sheets.Add.Cells(1).Resize(n, 3).Value = b
    End Sub

  6. #6
    Registered User
    Join Date
    05-26-2017
    Location
    Detroit, MI
    MS-Off Ver
    2010
    Posts
    3

    Re: Format 1 row in excel to many rows incrementally by range in row until blank cell

    Thank you all for your replies, I am just getting back from the long weekend and I will give your suggestions a try here in a bit! Thank you so much, I will post back with results.

  7. #7
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,957

    Re: Format 1 row in excel to many rows incrementally by range in row until blank cell

    Pleasure...Thanks for rep points
    Please mark thread as solved...
    Last edited by Sintek; 05-31-2017 at 05:04 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 3
    Last Post: 01-09-2017, 05:22 PM
  2. Copying COUNTIF across Columns but range changing incrementally
    By Staniel1975 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-02-2016, 10:54 PM
  3. Replies: 4
    Last Post: 09-24-2013, 05:44 AM
  4. Mac Excel: Hiding rows if cell blank, when being blank depends on a conditional formula
    By lee_5_5 in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 0
    Last Post: 06-06-2013, 11:25 PM
  5. Replies: 2
    Last Post: 02-07-2013, 04:50 PM
  6. Replies: 2
    Last Post: 09-20-2012, 11:30 AM
  7. Delete a range of rows above blank cell
    By d_rock90 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-07-2008, 10:45 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1