VBA Merge like cells in row with an exception

MrEd1534

New Member
Joined
Nov 29, 2013
Messages
15
Hello. I have a VBA code to merge multiple rows based on like values . Below is an excerpt of the raw data (1st Image). My data range is actually Columns A through H, but that doesn't seem relevant to my question. My code will do exactly what I want except when I have the Job Duty Percentage of a Job Duty Number equal to the Job Duty Percentage of a different Job Duty Number. Job Duty Number 2 and Job Duty Number 3 are both 20 percent each of the total. When my code runs it looks like 2md Image below. How can I modify my code that the 20 % shows next to each Job Duty Description instead of the 20 showing as a shared value?


VBA Code:
Option Explicit


Sub Merge_Same_Cells()

Application.DisplayAlerts = False

Dim rng As Range

Worksheets("RawData").Range("A6:H1500").Select

MergeCells:

For Each rng In Selection

If rng.Value = rng.Offset(1, 0).Value And rng.Value <> "" Then
Range(rng, rng.Offset(1, 0)).Merge
Range(rng, rng.Offset(1, 0)).HorizontalAlignment = xlCenter
Range(rng, rng.Offset(1, 0)).VerticalAlignment = xlCenter
GoTo MergeCells
End If

Next
?

1st Image.
VBA Merge.JPG


2nd Image.

VBA Merge2.JPG
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

Forum statistics

Threads
1,214,376
Messages
6,119,180
Members
448,871
Latest member
hengshankouniuniu

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