Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8609919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:59:44+00:00 2026-06-12T03:59:44+00:00

I am trying to get Excel data, which was mapped using a grid/matrix mapping

  • 0

I am trying to get Excel data, which was mapped using a grid/matrix mapping into a de-normalized for so that i can enter the data into a database.

How do you copy data in a grid from one excel sheet to the other as follow illustrated below.
enter image description here

I was trying something like this… but as you can see, i am far off!

Sub NormaliseList(mySelection As Range)
Dim cell As Range
Dim i As Long
i = 1
    For Each cell In mySelection
        If cell <> "" Then
                Sheets(2).Range("A" & i).Value = cell(cell.Row, 1).Value
                Sheets(2).Range("B" & i).Value = cell.Value
                Sheets(2).Range("C" & i).Value = cell(1, cell.Column).Value
                i = i + 1

    Next cell
End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T03:59:45+00:00Added an answer on June 12, 2026 at 3:59 am

    I’ve got two posts, with usable code and downloadable workbook, on doing this in Excel/VBA on my blog:

    http://yoursumbuddy.com/data-normalizer

    http://yoursumbuddy.com/data-normalizer-the-sql/

    Here’s the code:

    'Arguments
    'List: The range to be normalized.
    'RepeatingColsCount: The number of columns, starting with the leftmost,
    '   whose headings remain the same.
    'NormalizedColHeader: The column header for the rolled-up category.
    'DataColHeader: The column header for the normalized data.
    'NewWorkbook: Put the sheet with the data in a new workbook?
    '
    'NOTE: The data must be in a contiguous range and the
    'rows that will be repeated must be to the left,
    'with the rows to be normalized to the right.
    
    Sub NormalizeList(List As Excel.Range, RepeatingColsCount As Long, _
        NormalizedColHeader As String, DataColHeader As String, _
        Optional NewWorkbook As Boolean = False)
    
    Dim FirstNormalizingCol As Long, NormalizingColsCount As Long
    Dim ColsToRepeat As Excel.Range, ColsToNormalize As Excel.Range
    Dim NormalizedRowsCount As Long
    Dim RepeatingList() As String
    Dim NormalizedList() As Variant
    Dim ListIndex As Long, i As Long, j As Long
    Dim wbSource As Excel.Workbook, wbTarget As Excel.Workbook
    Dim wsTarget As Excel.Worksheet
    
    With List
        'If the normalized list won't fit, you must quit.
       If .Rows.Count * (.Columns.Count - RepeatingColsCount) > .Parent.Rows.Count Then
            MsgBox "The normalized list will be too many rows.", _
                   vbExclamation + vbOKOnly, "Sorry"
            Exit Sub
        End If
    
        'You have the range to be normalized and the count of leftmost rows to be repeated.
       'This section uses those arguments to set the two ranges to parse
       'and the two corresponding arrays to fill
       FirstNormalizingCol = RepeatingColsCount + 1
        NormalizingColsCount = .Columns.Count - RepeatingColsCount
        Set ColsToRepeat = .Cells(1).Resize(.Rows.Count, RepeatingColsCount)
        Set ColsToNormalize = .Cells(1, FirstNormalizingCol).Resize(.Rows.Count, NormalizingColsCount)
        NormalizedRowsCount = ColsToNormalize.Columns.Count * .Rows.Count
        ReDim RepeatingList(1 To NormalizedRowsCount, 1 To RepeatingColsCount)
        ReDim NormalizedList(1 To NormalizedRowsCount, 1 To 2)
    End With
    
    'Fill in every i elements of the repeating array with the repeating row labels.
    For i = 1 To NormalizedRowsCount Step NormalizingColsCount
        ListIndex = ListIndex + 1
        For j = 1 To RepeatingColsCount
            RepeatingList(i, j) = List.Cells(ListIndex, j).Value2
        Next j
    Next i
    
    'We stepped over most rows above, so fill in other repeating array elements.
    For i = 1 To NormalizedRowsCount
        For j = 1 To RepeatingColsCount
            If RepeatingList(i, j) = "" Then
                RepeatingList(i, j) = RepeatingList(i - 1, j)
            End If
        Next j
    Next i
    
    'Fill in each element of the first dimension of the normalizing array
    'with the former column header (which is now another row label) and the data.
    With ColsToNormalize
        For i = 1 To .Rows.Count
            For j = 1 To .Columns.Count
                NormalizedList(((i - 1) * NormalizingColsCount) + j, 1) = .Cells(1, j)
                NormalizedList(((i - 1) * NormalizingColsCount) + j, 2) = .Cells(i, j)
            Next j
        Next i
    End With
    
    'Put the normal data in the same workbook, or a new one.
    If NewWorkbook Then
        Set wbTarget = Workbooks.Add
        Set wsTarget = wbTarget.Worksheets(1)
    Else
        Set wbSource = List.Parent.Parent
        With wbSource.Worksheets
            Set wsTarget = .Add(after:=.Item(.Count))
        End With
    End If
    
    With wsTarget
        'Put the data from the two arrays in the new worksheet.
       .Range("A1").Resize(NormalizedRowsCount, RepeatingColsCount) = RepeatingList
        .Cells(1, FirstNormalizingCol).Resize(NormalizedRowsCount, 2) = NormalizedList
    
        'At this point there will be repeated header rows, so delete all but one.
       .Range("1:" & NormalizingColsCount - 1).EntireRow.Delete
    
        'Add the headers for the new label column and the data column.
       .Cells(1, FirstNormalizingCol).Value = NormalizedColHeader
        .Cells(1, FirstNormalizingCol + 1).Value = DataColHeader
    End With
    End Sub
    

    You’d call it like this:

    Sub TestIt()
    NormalizeList ActiveSheet.UsedRange, 1, "Name", "Count", False
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write an Excel add-in that can get data from a web
I'm trying to get my program to dump out data into an Excel spreadsheet.
I'm trying to read an excel file from C# using COM, and can get
I am trying to create a csv file using python that is truly Excel-compatible
I have an excel file which I am trying to put into mysql. There
I'm trying to read data from an Excel document in C# using Microsofts COM
I am trying to get data from Excel File to DataTable. Here's my code-snippet
I have a table that contains data that I am trying to import into
I am trying to get excel to follow patterns grabbing information from cells only,
I'm trying to get an Excel function to return more arguments than are passed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.