Solved

Excel: Add Paste As Number to Code

Posted on 2015-02-03
6
85 Views
Last Modified: 2015-02-03
Hello,

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
        Range("S12").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.
0
Comment
Question by:dabug80
  • 3
  • 3
6 Comments
 
LVL 23

Expert Comment

by:Michael74
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

0
 
LVL 1

Author Comment

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

Expert Comment

by:Michael74
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

to
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

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:dabug80
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.
0
 
LVL 23

Accepted Solution

by:
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
0
 
LVL 1

Author Closing Comment

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

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

696 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