VBA to merge rows if A:A is the same

GazNicki

Board Regular
Joined
Nov 30, 2010
Messages
79
Hi

I am looking for the VBA code needed to merge rows of data where the information in the A column is the same. Below is a Mini Sheet.

What I want the code to do is merge the rows where the data in A is the same. In the example below, you can see that NC2021-007 is found on row 8 and row 11. I would like these rows to merge leaving me with one single row which contains all the information.

Cells B to I will always be blank on the second instance of the repeated reference.
Cells K to Q will always be blank on the first instance of the repeated reference.
Cell A will be the only cell with the duplicated content, and should be replaced with the content from the second instance.

Non Conformance Tracker - 2021 (Table).xlsm
ABCDEFGHIJKLMNOPQ
1ReferenceIssue NameIssue DateCreated by NameCreated By EmailDescriptionSeverityPerson ResponsiblePR EmailDeadlineNC Complete?CA TakenDate CompleteCompleted ByClosed?Review ByDate Closed
2NC2021-001Test 1215/11/2021Kerry ElfordTest@test.comTesting yet againPaul BloorTest@test.com16/11/2021
3NC2021-002rvghbnjkm19/11/2021Sarah SheldonTest@test.comgfhvbjnkm,llkjbhvgPaul BloorTest@test.com16/12/2021
4NC2021-003trfdvvs15/10/2021Marzena DudekTest@test.comthfdscKerry ElfordTest@test.com21/10/2021
5NC2021-004Test New22/10/2021Gareth ParkinsonTest@test.comThis tests the SeverityHighMarzena DudekTest@test.com12/12/2021
6NC2021-005Test22/10/2021Gareth ParkinsonTest@test.comThis is a testHighKerry ElfordTest@test.com29/10/2021
7NC2021-006Test 222/10/2021Gareth ParkinsonTest@test.comThis is just a TestHighMarzena DudekTest@test.com29/10/2021
8NC2021-007Final Test22/10/2021Marzena DudekTest@test.comThis is a test of the NC ReportHighKerry ElfordTest@test.com29/10/2021
9NC2021-008Testing, yet again22/10/2021Kerry ElfordTest@test.comThis is a test to ensure that the correct person receives the email.MediumRod LedgardTest@test.com05/11/2021
10NC2021-009FRIDAY 22/10/2021Marzena DudekTest@test.comFRIDAY - LETS GO HOME MediumJimmy WinstanleyTest@test.com05/11/2021
11NC2021-007  YesThis is the Corrective Action that has been fixed.27/10/2021Kerry ElfordYesGareth Parkinson27/10/2021
NC Log
Cell Formulas
RangeFormula
A2:A10A2=IF(C2="","",CONCATENATE("NC",TEXT(C2,"YYyy")&"-",LEFT("00",4-LEN(ROW(A2)-1)),ROW(A2)-1))
E11E11=IF(D11="","",VLOOKUP(D11,Table1,2,FALSE))
I11I11=IF(H11="","",VLOOKUP(H11,Table2,2,FALSE))
Named Ranges
NameRefers ToCells
'CA Form'!CreatedBy=Table1[Created By (Name)]E11
CreatedBy=Table1[Created By (Name)]E11
'CA Form'!PersonResponsible=Table2[Responsible (Name)]I11
PersonResponsible=Table2[Responsible (Name)]I11
Cells with Conditional Formatting
CellConditionCell FormatStop If True
G2:G99Cell Valuecontains "Low"textNO
G2:G99Cell Valuecontains "Medium"textNO
G2:G99Cell Valuecontains "High"textNO
 
try this code, Note it doesn't delete the row, just the contents so you will end up with blanks rows. You didn't say which you wanted.
VBA Code:
Sub test()
Dim tempr(1 To 1, 1 To 7) As Variant

lastrow = Cells(Rows.Count, "A").End(xlUp).Row
inarr = Range(Cells(1, 1), Cells(lastrow, 17))

For i = 2 To lastrow - 1
 For j = i + 1 To lastrow
  If inarr(i, 1) = inarr(j, 1) Then
    For k = 1 To 7
     tempr(1, k) = inarr(j, 10 + k)
    Next k
    Range(Cells(i, 11), Cells(i, 17)) = tempr
    Range(Cells(j, 1), Cells(j, 17)) = ""
    Exit For
  End If
 Next j
Next i
End Sub
 
Upvote 0
Solution
Thanks for this offthelip.

This worked perfectly, and I have been able to work with the additional row by incorporating a sort function then deleting empty rows.

Really appreciate the help, it's helped me close off another question as a workaround.
 
Upvote 0

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