Excel: Add Paste As Number to Code


I have the following Code:

Sub mac_transfertoPOsummary()
' mac_transfertoPOsummary Macro

' This macro copies the information on the PO template and pastes this information to the next available row on the PO Request summary.

Sheets("PO Template").Select
        Sheets("PO Template").Range("S12").Copy Destination:=Sheets("PO Request Summary").Range("E7").End(xlDown).Offset(1, 0)
End Sub

Open in new window

I would like to modify this to paste the value as a number. But I don't know how to add this code correctly:
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False

Open in new window

Can you help.
Who is Participating?
Michael FowlerConnect With a Mentor Solutions ConsultantCommented:
Is working correctly for me??

Try changing it to

Sheets("PO Request Summary").Range("E" & Rows.Count).End(xlUp).Offset(1, 0) = Sheets("PO Template").Range("S12").Value

Open in new window

This finds the first used cell from the bottom up and so allows for some cells in the column to be empty.

If does not work could you please post your workbook
Michael FowlerSolutions ConsultantCommented:
No need to use copy/paste for this just use
Sheets("PO Request Summary").Range("E7") = Sheets("PO Template").Range("S12").Value

Open in new window

If needed you can also format the cell as a number using
Sheets("PO Request Summary").Range("E7").NumberFormat = "0"

Open in new window

dabug80Author Commented:
Sorry, how does this integrate with my offset code?
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Michael FowlerSolutions ConsultantCommented:
After a second look at your question I believe what you are after is

to copy the value in cell
Sheets("PO Template").Range("S12")

Open in new window

Sheets("PO Request Summary").Range("E7").End(xlDown).Offset(1, 0)

Open in new window

and ensure that it is displayed as a number

This line will achieve that goal. There is no need to use copy/paste in this case
Sheets("PO Request Summary").Range("E7").End(xlDown).Offset(1, 0) = Sheets("PO Template").Range("S12").Value

Open in new window

Additionally if the cell is not correctly formated as a number after this operation you fix this using
 Sheets("PO Request Summary").Range("E7").End(xlDown).NumberFormat = "0"

Open in new window

dabug80Author Commented:
Thanks. The code copies everything across correctly - but when the macro is run twice, the data is copied to the same location.

It seems like the formula isn't correctly offsetting to the next blank cell with subsequent macro triggers.
dabug80Author Commented:
Great. Works perfectly now. Thanks so much for taking the time to troubleshoot with me.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.