Supress overwrite destination cells message in vba

Robie
5StarLounger
Posts: 656
Joined: 18 Feb 2010, 14:26

Supress overwrite destination cells message in vba

Post by Robie »

Hi

I am using the code as follows to copy a column range to another sheet using the following code:

Code: Select all

                With Sheets(sFromSheet)
                    m = .Cells(.Rows.Count, COL2SETCROSSORTICK).End(xlUp).Row
                    Set CopyFrom = .Range(.Cells(1, COL2SETCROSSORTICK), .Cells(m, COL2SETCROSSORTICK))
                End With
                With Sheets(sToSheet)
                    Set CopyTo = .Range(.Cells(4, Col2CopyInto), .Cells(m, Col2CopyInto))
                    CopyTo.Clear
                End With
                CopyFrom.Copy CopyTo
                 ...
                 ...
The copy works fine(I also clear the copyto range just in case) but I get the message about overwriting destination cells as follows: Is there any way to avoid this message?
59.png
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78869
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Supress overwrite destination cells message in vba

Post by HansV »

Insert a line

Code: Select all

    Application.DisplayAlerts = False
above the code that copies the cells, and

Code: Select all

    Application.DisplayAlerts = True
below it.
Best wishes,
Hans

Robie
5StarLounger
Posts: 656
Joined: 18 Feb 2010, 14:26

Re: Supress overwrite destination cells message in vba

Post by Robie »

HansV wrote:Insert a line

Code: Select all

    Application.DisplayAlerts = False
above the code that copies the cells, and

Code: Select all

    Application.DisplayAlerts = True
below it.
Fantastic Hans. Thank you very much. :clapping: