Solved

Excel row and column as one record

Posted on 2014-07-21
1
564 Views
Last Modified: 2014-07-23
Hello Experts Exchange
I have a spreadsheet that has a table of data, the has product information going down the left of the row and date information going across the top.

Is it possible to get the product information and the date information in one row in Excel, so I can import the records into SQL Server?

I have attached how the data is on sheet1 and on sheet2 I have added a example of how I want the data.

Regards

SQLSearcher
Losses-Example.xls
0
Comment
Question by:SQLSearcher
1 Comment
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
Comment Utility
This macro seems to do the trick for me.  Make sure to update the start date, and the range to evaluate (in that range, do not include the total column).

Sub Normalize()
    
    Dim SourceRange As Range
    Dim SourceArr As Variant
    Dim r As Long, c As Long
    Dim DestR As Long
    
    ' Update as needed
    
    Const StartDate As Date = #6/1/2014#
    
    ' Update as needed
    
    Set SourceRange = ActiveSheet.Range("a1:ak13")
    
    SourceArr = SourceRange.Value
    
    Worksheets.Add
    
    Range("a1:f1").Value = Array("Die", "Machine", "Part Desc", "Part No", "Date", "Units")
    DestR = 2
    
    For r = 4 To UBound(SourceArr, 1)
        For c = 7 To UBound(SourceArr, 2)
            If SourceArr(r, c) <> "" Then
                Cells(DestR, 1) = SourceArr(r, 1)
                Cells(DestR, 2) = SourceArr(r, 2)
                Cells(DestR, 3) = SourceArr(r, 3)
                Cells(DestR, 4) = SourceArr(r, 4)
                Cells(DestR, 5) = StartDate + SourceArr(1, c) - 1
                Cells(DestR, 6) = SourceArr(r, c)
                DestR = DestR + 1
            End If
        Next
    Next
    
    MsgBox "Done"
    
End Sub

Open in new window

0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Need a poor man's PowerPoint 5 34
Merging multiple rows to one 22 32
Copy the formula in excel 8 22
MS Office subscription 11 30
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Outlook Free & Paid Tools
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now