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
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
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
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
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!!!
Thank you!! This worked perfectly!
Both sintek and jindon's solution worked
Thanks so much!
![]()
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
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.
Pleasure...Thanks for rep points
Please mark thread as solved...
Last edited by Sintek; 05-31-2017 at 05:04 AM.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks