Create a table with a specific number of rows

Undina

New Member
Joined
Nov 19, 2023
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi, I have 0 coding experience and am hoping someone can help me solve a fairly simple task. Say, I have a table with 5 rows and 3 columns. Let's say row names are Uno, Due, Tre, QUattro, Cinque, and column names are Alpha, Beta, Gamma. Users input numerical values in cells in this table. I need to create a new table in a separate tab where each row is: First Column - name of the row from original
Second Column: name of the column from original
Third Column - a drop down list, same list for all the rows
And most importantly, the number of rows equals the number that the user inputted in the original table for the cmbination. So I need to take this:
1700424635280.png

And transform into this:
1700424702415.png


I hope this makes sesne. Any help would be greatly appreciated.
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Hi Undina,

Welcome to MrExcel!!

Apart from the drop-down this will do what you're after:

VBA Code:
Option Explicit
Sub Macro1()

    Dim wsSrc As Worksheet, wsDestin As Worksheet
    Dim lngRow As Long, lngRowFrom As Long, lngRowTo As Long, lngRowPaste As Long, lngRecCount As Long
    Dim lngCol As Long, lngColFrom As Long, lngColTo As Long 'Columns
    
    Application.ScreenUpdating = False
    
    Set wsSrc = ThisWorkbook.Sheets("Sheet1") '<-Sheet name containing the raw data. Change to suit.
    Set wsDestin = ThisWorkbook.Sheets("Sheet2") '<-Sheet name for the formatted raw data. Change to suit.
    
    lngRowFrom = 2
    lngRowTo = wsSrc.Cells(Rows.Count, "A").End(xlUp).Row
    lngColFrom = 2
    
    For lngRow = lngRowFrom To lngRowTo
        lngColTo = wsSrc.Cells(lngRow, Columns.Count).End(xlToLeft).Column
        For lngCol = lngColFrom To lngColTo
            If wsSrc.Cells(lngRow, lngCol) > 0 Then
                lngRecCount = wsSrc.Cells(lngRow, lngCol)
                lngRowPaste = IIf(lngRowPaste = 0, 1, wsDestin.Cells(Rows.Count, "A").End(xlUp).Row + 1)
                wsDestin.Range("A" & lngRowPaste & ":A" & (lngRowPaste + lngRecCount) - 1).Value = wsSrc.Cells(lngRow, 1)
                wsDestin.Range("B" & lngRowPaste & ":B" & (lngRowPaste + lngRecCount) - 1).Value = wsSrc.Cells(1, lngCol)
            End If
        Next lngCol
    Next lngRow
    
    Application.ScreenUpdating = True

End Sub

For the drop-down I need more information - what is the list? Is it in a sheet and if so what's the cell address or its named range?

Regards,

Robert
 
Upvote 0
Hi Undina,

Welcome to MrExcel!!

Apart from the drop-down this will do what you're after:

VBA Code:
Option Explicit
Sub Macro1()

    Dim wsSrc As Worksheet, wsDestin As Worksheet
    Dim lngRow As Long, lngRowFrom As Long, lngRowTo As Long, lngRowPaste As Long, lngRecCount As Long
    Dim lngCol As Long, lngColFrom As Long, lngColTo As Long 'Columns
   
    Application.ScreenUpdating = False
   
    Set wsSrc = ThisWorkbook.Sheets("Sheet1") '<-Sheet name containing the raw data. Change to suit.
    Set wsDestin = ThisWorkbook.Sheets("Sheet2") '<-Sheet name for the formatted raw data. Change to suit.
   
    lngRowFrom = 2
    lngRowTo = wsSrc.Cells(Rows.Count, "A").End(xlUp).Row
    lngColFrom = 2
   
    For lngRow = lngRowFrom To lngRowTo
        lngColTo = wsSrc.Cells(lngRow, Columns.Count).End(xlToLeft).Column
        For lngCol = lngColFrom To lngColTo
            If wsSrc.Cells(lngRow, lngCol) > 0 Then
                lngRecCount = wsSrc.Cells(lngRow, lngCol)
                lngRowPaste = IIf(lngRowPaste = 0, 1, wsDestin.Cells(Rows.Count, "A").End(xlUp).Row + 1)
                wsDestin.Range("A" & lngRowPaste & ":A" & (lngRowPaste + lngRecCount) - 1).Value = wsSrc.Cells(lngRow, 1)
                wsDestin.Range("B" & lngRowPaste & ":B" & (lngRowPaste + lngRecCount) - 1).Value = wsSrc.Cells(1, lngCol)
            End If
        Next lngCol
    Next lngRow
   
    Application.ScreenUpdating = True

End Sub

For the drop-down I need more information - what is the list? Is it in a sheet and if so what's the cell address or its named range?

Regards,

Robert
Robert,
Thank you so so so much! Life saver!!
 
Upvote 0

Forum statistics

Threads
1,215,095
Messages
6,123,073
Members
449,093
Latest member
ripvw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top