Solved

Excel: Add Paste As Number to Code

Posted on 2015-02-03
6
75 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
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…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now