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 8893153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:10:35+00:00 2026-06-14T23:10:35+00:00

Consider a table: a b c d key1 value1 value2 value3 key2 value1a value3a

  • 0

Consider a table:

a       b        c       d
key1   value1   value2   value3
key2   value1a           value3a

i need to convert this into

Key1 Value1
Key1 Value2
Key1 Value3
Key2 Value1a
Key2 
key2 Value3a

this code, works in putting all the data into a single column, including spaces as required, but i need to keep the first column as a key and I’m new to VBA in excel.

  Sub MultiColsToA() 
Dim rCell As Range 
Dim lRows As Long 
Dim lCols As Long 
Dim lCol As Long 
Dim ws As Worksheet 
Dim wsNew As Worksheet 

lCols = Columns.Count 
lRows = Rows.Count 
Set wsNew = Sheets.Add() 

For Each ws In Worksheets 
    With ws 
        For Each rCell In .Range("B1", .Cells(1, lCols).End(xlToLeft)) 
            .Range(rCell, .Cells(lRows, rCell.Column).End(xlUp)).Copy _ 
            wsNew.Cells(lRows, 1).End(xlUp)(2, 1) 
        Next rCell 
    End With 
Next ws 

End Sub 

The tables are approximately 55 rows with 12 to 30 columns.
I ideally also need to convert 20 or so sheets in the same way, so a programmatic way of doing this would be ideal, can SO help?

  • 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-14T23:10:36+00:00Added an answer on June 14, 2026 at 11:10 pm

    Here is a basic example of how you could get something like that working. Hopefully this will be helpful as a concept and you can tweak to best suit what you’re looking for:

    Sub MultiColsToA()
    
        Dim rCell As Range
        Dim cCell As Range
        Dim iCounter As Integer
        Dim iInner As Integer
        Dim ws As Worksheet
        Dim wsNew As Worksheet
    
        ' Find the full range of the original sheet (assumes each row
        ' in column A will have a value)
        Set rCell = Range("A1:A" & Range("A1").End(xlDown).Row)
        Set wsNew = Sheets.Add()
    
        For Each ws In Worksheets
            ' Set our sentinel counter to track the row
            iCounter = 1
    
            ' Iterate through each cell in the original sheet
            For Each cCell In rCell
    
              ' This will likely need to be adjusted for you, but
              ' here we set a counter = 1 to the number of columns
              ' the original sheet contains (here 3, but can be changed)
              For iInner = 1 To 3
                  With wsNew
                      ' Set the first column = the key and the second the
                      ' proper value from the first sheet
                      .Cells(iCounter, 1).Value = cCell.Value
                      .Cells(iCounter, 2).Value = cCell.Offset(0, iInner).Value
                  End With
    
                  ' Increment the sentinel counter
                  iCounter = iCounter + 1
              Next iInner
            Next cCell
        Next ws
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider this table: c_const code | nvalue -------------- 1 | 10000 2 | 20000
i need a complex query: Consider this table: ID - field1 - field2 =================
Consider this table on SQL Server wordID aliasID value =========================== 0 0 'cat' 1
Consider a table or CTE structured like this: Name Num ---- ---- Abc 12
please consider this table: PK_Id Number Year Month Value ------------------------------------------------------------------------- 1 1 2000 5
I am trying to accomplish this: Consider a table view with Search Bar on
Consider this table (from http://www.tizag.com/mysqlTutorial/mysqlmax.php ): Id name type price 123451 Park's Great Hits
Consider a table datatbl like this: +----------+ | strfield | +----------+ | abcde |
Consider a table like this: | Name | Version | Other | | ---------------------|-------|
Consider a table like this: folders_table ----------------------- INT id_folder INT id_folder_parent VARCHAR folder_name Which

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.