VBA - Copying and Pasting the Formatting

AmeliaBedelia

New Member
Joined
Apr 8, 2018
Messages
19
I am having difficulty with some VBA code that copies a cell value ("P4") on one sheet ("Form") and pastes it into another cell on different sheet ( Last row in column A on "Tracking" Sheet). When it pastes the value, it shows on the Home>Number menu that it is formatted as a number, but a warning message appears in the cell (green triangle in top left of cell) stating that the "Number stored as Text". This is impacting its ability to use the value in formulas.

Is there a way to add something to the code below to get rid of this warning message or stop it from storing the number as text? I want it to show up as a number with no decimal points.

If Sheets("Form").Range("A4").Value = "Correction" Then
Set SourceRange = Sheets("Form").Range("P4")
Set DestSheet = Sheets("Tracking")
lr = DestSheet.Cells(Rows.Count, "A").End(xlUp).Row
Set DestRange = DestSheet.Range("A" & lr + 1)

Sheets("Tracking").Select
SourceRange.Copy
DestRange.PasteSpecial _
Paste:=xlPasteValuesAndNumberFormats, _
Paste:=xlPasteFormats,_
Operation:=xlPasteSpecialOperationNone, _
SkipBlanks:=False, _
Transpose:=True
Application.CutCopyMode = False
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
I am having difficulty with some VBA code that copies a cell value ("P4") on one sheet ("Form") and pastes it into another cell on different sheet ( Last row in column A on "Tracking" Sheet). When it pastes the value, it shows on the Home>Number menu that it is formatted as a number, but a warning message appears in the cell (green triangle in top left of cell) stating that the "Number stored as Text". This is impacting its ability to use the value in formulas.

Is there a way to add something to the code below to get rid of this warning message or stop it from storing the number as text? I want it to show up as a number with no decimal points.

If Sheets("Form").Range("A4").Value = "Correction" Then
Set SourceRange = Sheets("Form").Range("P4")
Set DestSheet = Sheets("Tracking")
lr = DestSheet.Cells(Rows.Count, "A").End(xlUp).Row
Set DestRange = DestSheet.Range("A" & lr + 1)

Sheets("Tracking").Select
SourceRange.Copy
DestRange.PasteSpecial _
Paste:=xlPasteValuesAndNumberFormats, _
Paste:=xlPasteFormats,_
Operation:=xlPasteSpecialOperationNone, _
SkipBlanks:=False, _
Transpose:=True
Application.CutCopyMode = False
Just out of curiosity, if you replace what I highlighted in red with the following, does it work the way you want...

SourceRange.Copy DestRange
 
Upvote 0
No, unfortunately it does not. The cell it is copying from (P4) actually has a formula in it that calculates a number value. Changing the code as you indicated above copies over the formula.
 
Upvote 0

Forum statistics

Threads
1,215,063
Messages
6,122,935
Members
449,094
Latest member
teemeren

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