Help errors with formatting

Msears

Board Regular
Joined
Apr 14, 2022
Messages
56
Office Version
  1. 365
  2. 2021
  3. 2019
Platform
  1. Windows
Hello All, I have a workbook, with multiple worksheets. Each one of them have Active x buttons on them. I them all set to paste special values and formats. These work great the first time, but when I use my clear contents button (code below). The next time I initiate the action of copying the info, it forgets it on about half of them. If another attempt is made, it forgets even more of the formatting, even though all sheets are formatted original the same. Is there a fix for this? It is pretty annoying to have to reformat after each copy and paste. I have also included an example of a copy code for reference. Thanks in advance?

Clear button code
ActiveSheet.ShowAllData
With ActiveSheet
ActiveSheet.[A2:K500].SpecialCells(xlCellTypeConstants).ClearContents
ActiveSheet.[P2:Z500].SpecialCells(xlCellTypeConstants).ClearContents
End With
End Sub

Copy and Paste example
Dim FirstEmptyRow As Long
Dim Rng As Range
Set Rng = Range("P:Z")
Application.ScreenUpdating = False
With ActiveSheet
FirstEmptyRow = .Cells(.Rows.Count, "P").End(xlUp).Offset(1, 0).Row
ActiveSheet.Range("A2:K3000").Copy
.Cells(FirstEmptyRow, "P").PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:=xlNone, SkipBlanks:=True
End With
Rng.RemoveDuplicates Columns:=Array(1, 5), Header:=xlYes
Excel.Application.CutCopyMode = False
Application.ScreenUpdating = True
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

Forum statistics

Threads
1,214,653
Messages
6,120,749
Members
448,989
Latest member
mariah3

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