Checking and removing merged cells

mps80y

New Member
Joined
Apr 3, 2019
Messages
22
Hi,

I have a spreadsheet that for some unknown reason certain users love merging cells. We're in the process of stamping out that practice, but in the meantime as part of an import and VLOOKUP I need to be able to removed the merged calls.

The cells are G and H on the sheet and contain suburbs eg: [G: CENTRAL - LEICHHARDT -] [H: MERRYLANDS]

I am able to use VBA to identify the cells to the user but the process takes awhile to run. Is there any way to simply run a process so that it identifies a merged cell, unmerges it and replaces the values as below

[G: CENTRAL via LEICHHARDT] [H: MERRYLANDS]

(obviously the letter at the start represents the cell the value is in).

I'm new to Excel VBA so would appreciate any support.

Cheers
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Column G is 'Pick up Address' and Column H is 'Drop off Address'

The values in Cells G & H are merged for some rows and the content is always in the format 'CITY - CITY2 - CITY3'. Which means we picked up clients from City1 and dropped them at City3 via CITY2.

The problem is when I try to use the VLOOKUP function to retrieve data from columns G and H if they're merged I can't retrieve the value.

In the attached screenshot, lines 506 & 508 are correct, but I need a script to make 507 say something like 'Cell G: Lidcombe via Bankstown' and 'Cell H: Lidcombe'.

http://imgur.com/a/MVxOgbB

I hope this makes it somewhat clearer.
 
Upvote 0
Got it. Can you upload some sample data with at least one merged cell somewhere and post a link here so I have something to go on?
 
Upvote 0
This macro should do it:

Code:
Sub Unmerge()
    Dim oCell As Range
    Dim sVal As String
    For Each oCell In Intersect(ActiveSheet.UsedRange, Range("G:G"))
        If oCell.MergeCells Then
            sVal = oCell.Value
            oCell.Unmerge
            oCell.Value = Replace(Trim(Left(sVal, InStrRev(sVal, "-") - 1)), " - ", " via ")
            oCell.Offset(, 1).Value = Trim(Mid(sVal, InStrRev(sVal, "-") + 1, Len(sVal)))
        End If
    Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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