message box if there are merged cell and unmerged and run the macro

KalilMe

Active Member
Joined
Mar 5, 2021
Messages
343
Office Version
  1. 2016
Platform
  1. Windows
hi

I would pop up message with the warning sound when I try running any macro and there are many merged cells then show me two choices if I press ok then cancel merged cells and run the macro and if I press no . then nothing happens and doesn't work the macro
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Give this structure a try...
VBA Code:
Sub YourMacro()
  Dim Answer
  If Cells.MergeCells Or IsNull(Cells.MergeCells) Then
    Answer = MsgBox("You have merged cells, can I remove all of them?", vbYesNo Or vbDefaultButton2)
    If Answer = vbNo Then Exit Sub
  End If
  '
  ' Your macro code goes here
  '
End Sub
 
Upvote 0
that's excellent . about cancel merged cells yes your code works practically , but visually the merged cells keeps merged . it should cancel cells merging . may you fix it, please ?
last thing about the message . may you change properties of message to become rough sound instead of show without any sound to warn.
 
Upvote 0
Sorry, I thought you already had that as part of your existing code. One line of code is all it takes...
Rich (BB code):
Sub YourMacro()
  Dim Answer
  If Cells.MergeCells Or IsNull(Cells.MergeCells) Then
    Answer = MsgBox("You have merged cells, can I remove all of them?", vbYesNo Or vbDefaultButton2)
    If Answer = vbNo Then Exit Sub
  End If
  Cells.Unmerge
  '
  ' Your macro code goes here
  '
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,636
Messages
6,120,668
Members
448,977
Latest member
moonlight6

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