Disable alert message when merging cells

Brass Contributor

Hello team,

 

I'm developing macro to generate separate copy from master template.

within master template I have multiple worksheets and within worksheet few cells are merged.

when I create copy from master template due to merge cell, I'm getting pop up alert. 

"Merging cells only keeps the upper-left value and discards other values."

 

Is there any way I can turn this alert off while creating a copy?

4 Replies

@Sumit_Bhokare 
Application.DisplayAlert = False

Hello @Sumit_Bhokare this throws an error:

DadoSljeme_0-1706866036102.png

 

@DadoSljeme That's Application.DisplayAlerts (with an s). Caution should be taken when disabling alerts... it's highly recommended to use error handling of some sort in order to make sure alerts are always turned back on. For example:

 

    On Error Resume Next
    Application.DisplayAlerts = False
        'your code here...
    Application.DisplayAlerts = True
    If Err.Number <> 0 Then
        MsgBox Err.Description, vbExclamation, "Runtime Error: " & Err.Number
        Err.Clear
    End If
    On Error GoTo 0

Many thanks @djclements of course Application.DisplayAlerts . I limit exactly only the area of the code, where I know there are Alerts that would block the flow but are safe to be turned off. Unfortunately Excel VBA does not offer to suppress them in the function itself, for example in the .merge method.