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
I added a second loop in your macro to achieve the results I as understood them:
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.