TechArena Community

TechArena Community (http://forums.techarena.in/)
-   Software Development (http://forums.techarena.in/software-development/)
-   -   Problem in macro for special paste (http://forums.techarena.in/software-development/1267607.htm)

RyanInt 06-11-2009 12:01 AM

Problem in macro for special paste
 
I have a problem with a macro that performs a Special Paste (values without copying formulas) to a new workbook after clicking a button and record the new workbook.

Here is the code used:

Code:

Public Sub CommandButton1_Click()
sort = "Sort" & ".xlsx"
ActiveSheet.Select
Range("A1:B7" ).Select
Selection.Copy
Workbooks.Add.SaveAs sort
Worksheets.Add.Name = "Consumption"
Workbooks(sort).Activate
Sheets("Consumption" ).Select
Range("A1" ).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Workbooks(sort).Save
Workbooks(sort).Close
End Sub


!const 06-11-2009 12:07 AM

Re: Problem in macro for special paste
 
It is "simple enough" in fact. Clear your Excel Copy after another action. Whether it's in code, or "normal" utilization.

Besides, you should have seen that your selection was not as small dots flashing on a copy.

You have copied and pasted almost to the following.
  • You created your new file.
  • You can chat live with your first file.
  • You copy your selection.
  • You can chat live with your new file.
  • You paste.
  • Enjoy

Code:

Public Sub CommandButton1_Click()
    sort = "Sort" & ".xls"
    originalsheet = ActiveSheet.Name
    originalclass = ActiveWorkbook.Name
    Workbooks.Add.SaveAs sort
    Worksheets.Add.Name = "Consumption"

    Workbooks(originalclass).Activate
    Sheets(originalsheet).Select
    Range("A1:B7" ).Select
    Selection.Copy
 
    Workbooks(sort).Activate
    Sheets("Consumption" ).Select
    Range("A1" ).Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    Workbooks(sort).Save
    Workbooks(sort).Close
End Sub


RyanInt 06-11-2009 12:09 AM

Re: Problem in macro for special paste
 
Thank you very much,

I still had a persistent error but removing the Range("A1" ).Select paste special before it works.

Now I have another concern, I wish it performs as a special paste when I paste values and number formats. In the current macro it only values, so I get to do only format. But the 2, I can not find?

!const 06-11-2009 12:10 AM

Re: Problem in macro for special paste
 
We must do both as a result no? A sudden you glue the values and formats.

Code:

'
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, SkipBlanks:=False, Transpose:=False

Or maybe I misunderstood the question .


All times are GMT +5.5. The time now is 08:35 PM.