vba IF statement help (cell formats)

UglyBunny

New Member
Joined
Aug 5, 2011
Messages
9
Hello,
I'm trying to write a few useful macros to help myself learn vba.
I've tried here to write some code that will determine whether or not the previously selected cells are merged, if they aren't then the cells should be merged together, if they are already then they should be unmerged.

Below is what I have so far, but I'm having difficulty finding the right expression for the IF statement, any tips for this would be appreciated!

Sub Merge()
'
' Merge Macro
'
' Keyboard Shortcut: Ctrl+m
'
If ???????? = True Then
With Selection
.MergeCells = False
End With
Else
With Selection
.MergeCells = True
.WrapText = True
End With
End If


End Sub
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Code:
Sub Merge_Unmerge()
    With Selection
        If .Cells(1).MergeArea.Address = .Address Then
            .UnMerge
        Else
            .Merge
        End If
    End With
End Sub

Or better readable:

Code:
Sub Merge_Unmerge()
    With Selection
        If .Cells(1).MergeArea.Address = .Address Then .UnMerge Else .Merge
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,548
Messages
6,179,448
Members
452,915
Latest member
hannnahheileen

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