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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:23:13+00:00 2026-06-17T18:23:13+00:00

I am trying to make edge relation from excel file which are organized in

  • 0

I am trying to make edge relation from excel file which are organized in rows,

A,B,C,

D,E

the aim is to create relationships from each row:

A,B

A,C

B,C

I have the following codes , the problem is the codes is efficient when rows are equal in length but for example for above rows it create also following edges (relationship):

D,” “

E, ” “

Which create big problem for large data set. I was wondering if some body can help me to adjust the code the way to create the edge list only till filled cells in each row. If there is any other way to do this more efficient will appreciate it.

Thank you so much,Will be great help.

My code:

Sub Transform()

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 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

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-17T18:23:14+00:00Added an answer on June 17, 2026 at 6:23 pm

    I’ve played around with it – this should do the trick. We can probably speed it up by outputting to another variant array if needed, but this ran pretty quickly for me:

    Sub Transform_New()
    
    Dim rngSource As Range, rngDest As Range
    Dim varArray As Variant
    Dim i As Integer, j As Integer, k As Integer
    
    Set rngSource = Sheet1.Range("A1", Sheet1.Cells(WorksheetFunction.CountA(Sheet1.Columns(1)), 1)) 'Put all used rows into range
    Set rngDest = Sheet1.Cells(WorksheetFunction.CountA(Sheet1.Columns(1)), 1).Offset(2, 0) 'Set target range to start 2 below source range
    
    varArray = Range(rngSource, rngSource.Offset(0, Range("A1").SpecialCells(xlCellTypeLastCell).Column)).Value
    
    For i = LBound(varArray, 1) To UBound(varArray, 1) 'Loop vertically through array
        For j = LBound(varArray, 2) To UBound(varArray, 2)    'Loop horizontally through each line apart from last cell
            k = j
            Do Until varArray(i, k) = ""
                    k = k + 1
                    If varArray(i, k) <> "" Then
                        rngDest.Value = varArray(i, j)
                        rngDest.Offset(0, 1).Value = varArray(i, k)
                        Set rngDest = rngDest.Offset(1, 0)
                    End If
            Loop
        Next
    Next
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to make the infamous checkall checkbox for dynamically created rows from a MySQL
I am trying to make an app that detects gestures swiped from the edge
I am fairly new to iOS development and trying make a simple app which
Trying to make a cross protocol, same domain request from https to http. I
I am trying to create a div that starts 200px from the left and
I am trying to make a slideshow from the book Javascript in 24 Hours
I'm trying to create a 2D array to represent a weighted graph. To make
I'm trying to make a CSS border that is on the very edge of
I'm trying to make a wheel, which will be sliced into different coloured sections
I'm trying to make a row layout with 2 columns like in this image

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.