Forum Discussion

abivens's avatar
abivens
Copper Contributor
Aug 27, 2025

Formatting Rows and Columns in Large Spreadsheet

I have a spreadsheet where Pledge IDs are displayed in Column A (thousands of rows), the the associated Pledge Payment IDs are on the same row, but extending for hundreds of columns.  Here is an example of the existing format, and how I need it to be formatted.  All suggestions would be most welcome.

Existing Format

Column A   Column B         Column C

Pledge ID   Payment 1 ID    Payment 2 ID

12345         4501                  4502

 

Required Format

Column A     Column B

Pledge ID      Payment ID

12345            4501

12345            4502

 

2 Replies

  • How about VBA Macro:

     

    Sub NormalizePledgePayments()
        Dim ws As Worksheet
        Set ws = ActiveSheet
    
        Dim lastRow As Long, lastCol As Long, outputRow As Long
        lastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row
        lastCol = ws.Cells(1, ws.Columns.Count).End(xlToLeft).Column
    
        Dim i As Long, j As Long
        outputRow = 1
        Sheets.Add.Name = "Normalized"
    
        For i = 2 To lastRow
            For j = 2 To lastCol
                If ws.Cells(i, j).Value <> "" Then
                    With Sheets("Normalized")
                        .Cells(outputRow, 1).Value = ws.Cells(i, 1).Value
                        .Cells(outputRow, 2).Value = ws.Cells(i, j).Value
                    End With
                    outputRow = outputRow + 1
                End If
            Next j
        Next i
    End Sub

     

Resources