Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Excel: Add Paste As Number to Code

Posted on 2015-02-03
Last Modified: 2015-02-03

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.
Question by:dabug80
  • 3
  • 3
LVL 23

Expert Comment

ID: 40587788
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


Author Comment

ID: 40587792
Sorry, how does this integrate with my offset code?
LVL 23

Expert Comment

ID: 40587795
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


Author Comment

ID: 40587804
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.
LVL 23

Accepted Solution

Michael74 earned 500 total points
ID: 40587813
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

Author Closing Comment

ID: 40587823
Great. Works perfectly now. Thanks so much for taking the time to troubleshoot with me.

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question