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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:00:55+00:00 2026-06-17T13:00:55+00:00

I have data as following in an excel sheet A,B,C D,E,F I would like

  • 0

I have data as following in an excel sheet

A,B,C
D,E,F

I would like to transform it to

A,B
A,C
B,C
D,E
D,F
E,F

I have following Macro, Which only can make this :

A,B
A,C
D,E
D,F

How can I adjust the following code to serve the purpose?

Dim targetRowNumber As Long
targetRowNumber = Selection.Rows(Selection.Rows.Count).Row + 2

Dim col1 As Variant
Dim cell As Range

Dim sourceRow As Range: For Each sourceRow In Selection.Rows

    col1 = sourceRow.Cells(1).Value
    For Each cell In sourceRow.Cells

        If Not cell.Column = Selection.Column Then
            Selection.Worksheet.Cells(targetRowNumber, 1) = col1
            Selection.Worksheet.Cells(targetRowNumber, 2) = cell.Value
            targetRowNumber = targetRowNumber + 1
        End If

    Next cell

Next sourceRow
  • 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-17T13:00:56+00:00Added an answer on June 17, 2026 at 1:00 pm

    I added a second loop in your macro to achieve the results I as understood them:

    Dim targetRowNumber As Long
    targetRowNumber = Selection.Rows(Selection.Rows.Count).Row + 2
    
    Dim col1 As Variant
    Dim cell As Range
    Dim colCounter As Long
    Dim colCounter2 As Long
    
    Dim sourceRow As Range: For Each sourceRow In Selection.Rows
    
        For colCounter = 1 To Selection.Columns.Count - 1
    
            'col1 = sourceRow.Cells(colCounter).Value
            'For Each cell In sourceRow.Cells
            col1 = sourceRow.Cells(colCounter).Value
            For colCounter2 = colCounter + 1 To Selection.Columns.Count
                Set cell = sourceRow.Cells(, colCounter2)
    
                If Not cell.Column = Selection.Column Then
                    Selection.Worksheet.Cells(targetRowNumber, 1) = col1
                    Selection.Worksheet.Cells(targetRowNumber, 2) = cell.Value
                    targetRowNumber = targetRowNumber + 1
                End If
    
            Next colCounter2
    
        Next colCounter
    
    Next sourceRow
    

    Note that performance would be greatly improved if you copy the selection into a local variable (array) to work off of, create the results in an array, and then copy the contents back to the sheet when you are done. That might not really matter unless you are working on much larger sets of data though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can't find the syntax error in the following Excel formula: I have data
I have data in an excel sheet in the following format: ItemCode DeliveryDate 5456987
Assume I have an Excel 2007 sheet with the following data in column A:
I have an excel sheet with data similar to the following Reg_id Name Product_Owned
I have following data in excel table r1 r2 r3 r4 r5 v1 v2
I have data like the following: var data = [{ id: 1, date: new
I have two columns in excel like the following a,apple a,bannana a,orange a,plum b,apple
I have file which contains the following data: -------------------[ server10 ]------------------- user1 user2 user99
I have a macro that add hundreds of lines of data to an excel
I'm importing data from an Excel sheet on to a DataTable using the following

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.