Combining rows of data

bydganwil

New Member
Joined
Jul 20, 2012
Messages
27
I have a set of data that looks like this:


Q1
Q2
Q3
Q4
Q5
Q6
Q7
Q8
Q9
Q10
Target 1
Y
Y
Y
Y
Target 1
Y
Y
Y
Target 1
Y
Y
Y
Target 2
Y
Y
Y
Target 2
Y
Y
Y
Target 2
Y
Y
Y
Y
Target 3
Y
Y
Y
Target 3
Y
Y
Y
Y
Target 3
Y
Y
Y

<TBODY>
</TBODY>


And I need it to look like this please:

Many thanks in advance!!
Q1
Q2
Q3
Q4
Q5
Q6
Q7
Q8
Q9
Q10
Target 1
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Target 2
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Target 3
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y

<TBODY>
</TBODY>
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

hurgadion

Active Member
Joined
Mar 19, 2010
Messages
426
Hi,
let Your Data be in A1:K10, then try to run a following code:
Code:
Sub abstract()
Dim a&, i&, j&, k&

a = Cells(Rows.Count, 1).End(xlUp).Row
Range("A1:A" & a).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range( _
        "M1"), Unique:=True

For i = 2 To Cells(Rows.Count, "M").End(xlUp).Row
    For j = 2 To a
       If Cells(j, 1).Value = Cells(i, "M").Value Then
          For k = 2 To 11
             If Cells(j, k).Value <> "" Then
                Cells(i, k + 12).Value = Cells(j, k).Value
             End If
          Next k
       End If
    Next j
Next i
End Sub
Best regards.
 
Last edited:
Upvote 0

patel45

Well-known Member
Joined
Jul 15, 2012
Messages
1,953
Code:
Sub a()
r = 3
numcol = 11
Do While Cells(r, 1) <> ""
  If Cells(r, 1) = Cells(r - 1, 1) Then
    For c = 2 To numcol
      If Cells(r - 1, c) = "" Then Cells(r - 1, c) = Cells(r, c)
    Next
    Rows(r).Delete
  Else
    r = r + 1
  End If

Loop
End Su
b
 
Upvote 0

kevatarvind

Well-known Member
Joined
Mar 3, 2013
Messages
1,047
Office Version
  1. 365
Platform
  1. Windows
let Your Data be in A1:K10, then try to run a following code:

Code:
Sub Test()
Dim rng As Range
Set rng = Range("B2:K10")
For Each Cell In rng
If Cell <> "" Then
Cell.Cut
Cells(WorksheetFunction.Match(Cells(Cell.Row, 1), Range("A1:A10"), 0), Cell.Column).Select
ActiveSheet.Paste
End If
Next
Columns("A:A").Select
  ActiveSheet.Range("$A$2:$K$10").RemoveDuplicates Columns:=1, Header:=xlNo
Range("A1").Select
End Sub
 
Last edited:
Upvote 0

bydganwil

New Member
Joined
Jul 20, 2012
Messages
27
ADVERTISEMENT
Hi there,

The code you provided is not doing anything that I can see. When I run the code it gets to the 1st For statement and then the sub ends. In addition the xlfiltercopy to range M1 is not writing any data in the worksheet (assuming I understand what your code is trying to do?)

Thanks for your time really appreciated!!!!
 
Upvote 0

kevatarvind

Well-known Member
Joined
Mar 3, 2013
Messages
1,047
Office Version
  1. 365
Platform
  1. Windows
let Your Data be in A1:K10, then try to run a following code:

Code:
Sub Test()
Dim rng As Range
Set rng = Range("B2:K10")
For Each Cell In rng
If Cell <> "" Then
Cell.Cut
Cells(WorksheetFunction.Match(Cells(Cell.Row, 1), Range("A1:A10"), 0), Cell.Column).Select
ActiveSheet.Paste
End If
Next
Columns("A:A").Select
  ActiveSheet.Range("$A$2:$K$10").RemoveDuplicates Columns:=1, Header:=xlNo
Range("A1").Select
End Sub
 
Upvote 0

hurgadion

Active Member
Joined
Mar 19, 2010
Messages
426
Try to write in A1 the word "Target" and then try to run my Code... best regards.

Hi there,

The code you provided is not doing anything that I can see. When I run the code it gets to the 1st For statement and then the sub ends. In addition the xlfiltercopy to range M1 is not writing any data in the worksheet (assuming I understand what your code is trying to do?)

Thanks for your time really appreciated!!!!
 
Upvote 0

Forum statistics

Threads
1,195,651
Messages
6,010,930
Members
441,573
Latest member
Goronvir

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
Top