VBA Code For Copying Worksheet And Pasting Values In Another Is Comingling Formats In A Column

DR RENO

Board Regular
Joined
Jun 29, 2018
Messages
65
I have two worksheets in same workbook to which I'm copying one to another and pasting special values. Column T is mixing currency and number formats. New to VBA, so any help you could provide would be appreciated.
Code:
Private Sub CommandButton3_Click()


Dim lLR As Long

Application.ScreenUpdating = False

With Sheets("CAR Open Contract")
    lLR = .Range("A1:T" & .Rows.Count).End(xlUp).Row
        .UsedRange.Copy
End With

With Sheets("PriorDay").Range("A1")
    .PasteSpecial _
        Paste:=xlPasteValuesAndNumberFormats, _
        Operation:=xlNone, _
        SkipBlanks:=False, _
        Transpose:=False
End With

Sheets("CAR Open Contract").Range("A1:T" & lLR).Copy
With Sheets("PriorDay").Range("A1")
    .PasteSpecial _
        Paste:=xlPasteFormats, _
        Operation:=xlNone, _
        SkipBlanks:=False, _
        Transpose:=False
End With


Application.CutCopyMode = False
Application.ScreenUpdating = True

End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
On the "CAR Open Contract" column "T" you only have one format?
Maybe it helps if you first clean the PriorDay sheet:

Code:
Private Sub CommandButton3_Click()
    Dim lLR As Long
    Application.ScreenUpdating = False
    
    Sheets("PriorDay").Cells.Clear
    
    With Sheets("CAR Open Contract")
        lLR = .Range("A" & Rows.Count).End(xlUp).Row
        .Range("A1:T" & lLR).Copy
    End With
    
    With Sheets("PriorDay").Range("A1")
        .PasteSpecial Paste:=xlPasteValuesAndNumberFormats
        .PasteSpecial Paste:=xlPasteFormats
    End With
    
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
On the "CAR Open Contract" column "T" you only have one format?
Maybe it helps if you first clean the PriorDay sheet:

Code:
Private Sub CommandButton3_Click()
    Dim lLR As Long
    Application.ScreenUpdating = False
    
    Sheets("PriorDay").Cells.Clear
    
    With Sheets("CAR Open Contract")
        lLR = .Range("A" & Rows.Count).End(xlUp).Row
        .Range("A1:T" & lLR).Copy
    End With
    
    With Sheets("PriorDay").Range("A1")
        .PasteSpecial Paste:=xlPasteValuesAndNumberFormats
        .PasteSpecial Paste:=xlPasteFormats
    End With
    
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
End Sub


Unfortunately still having same issue. I have various formatting types in columns A - T. Date, General, Number, and Currency. Each of the of the other columns correctly displays the correct formatting. However column T displays several rows of Number, then several rows of Currency. This sequence goes on until the final value. Since it's the final column in the range, I thought that may be causing the issue so extended range to column U. Column U formats correctly, but T is doing the same issue.
 
Upvote 0
Does it make any difference if you swap the paste commands round
Code:
    With Sheets("PriorDay").Range("A1")
        .PasteSpecial paste:=xlPasteFormats
        .PasteSpecial paste:=xlPasteValuesAndNumberFormats
    End With
 
Upvote 0
No still having same problem. What I did notice when trying your suggestion that I overlooked before is that Column N which is a Date format type is having the same issue as column T, although T is a Number format type. The each error in the same rows. N transitions from correct Date to rows of Number which is the same row sequence T is performing, except T transitions Number format type to Currency. There is no row pattern, as it will do 8-10 correctly and then 5 incorrect. The next 12 are correct then the next 6 or 7 are incorrect. Never had this happen before. I appreciate your guys help though.
 
Upvote 0
Not something I've ever encountered either.
Do you have any merged cells, or conditional formatting?
 
Upvote 0
No nothing merged or any conditional formatting in the table. It's a 3rd party data extract with the only modifications being the formulas I've put in to additional table columns. 2 of the 6 columns I've added are having this issue, while the other 4 are displaying the correct format type. If I go to the PriorData sheet and reformat it will display correctly, but don't want to have User being forced to do that.
 
Last edited:
Upvote 0
In the cells you have numbers and dates or they can be texts that appear to be numbers or dates.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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