VBA HELP - "If Sheet has no Meged Cells Do Nothing, If Merged Cells then Run Code" Excel 2013

magnum5az

New Member
Joined
Jun 21, 2017
Messages
16
Hello All,

I am working on a piece of code that will look at a specific sheet and if there are merged cells present run a code to remove all merged cells and move a header, if no merged cells exist on the sheet then do nothing.

Here is what I've come up with but need the "Case" or "If/Then" code

Code:
Sub ReOrgData()

    Dim Sourcesht As Worksheet
    
    Set Sourcesht = Sheets("AR Aging-Combined Property")
    
    
    Sourcesht.Cells.Select
    Selection.UnMerge
    Range("B2:B4").Select
    Selection.Cut
    Range("A2").Select
    ActiveSheet.Paste
    Rows("7:7").Select
    Selection.Delete Shift:=xlUp
    Application.CutCopyMode = False



End Sub

Thanks in advance for any help on this.
 
No, it is correct as originally written. Cells.MergeCells will return False if no merged cells exist, True if all cells are involved in a merge (a highly, highly unlikely scenario) and Null if the sheet contains a mixture of merged and non-merged cells. Since the mixture of merged and non-merged cells is what we are after (I completely discount a True result as such a sheet would be ridiculous), we need to test if Cells.MergeCells returns Null... IsNull does that (it will return True when MergeCells is Null).

Interesting...thanks for schooling me!
 
Upvote 0

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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