Selection.PasteSpecial

CThai

Active Member
Joined
Mar 18, 2007
Messages
295
Hello,

I need some help with a simple marco.... I did a recording marco to "copy" and "PasteSpecial" , select only the "Values" but i need to have it loop all the worksheets... currently i have 40 workbooks, with 58 worksheets, that I have to copy and paste manually... below is the code that i got when i did a recording marco... can you please help me narrow it down and loop though the workbooks

Code:
Sub value_test()
'
' value_test Macro
' Macro recorded 
'

'
    Cells.Select
    Application.CutCopyMode = False
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Sheets("Apr").Select
    Cells.Select
    Application.CutCopyMode = False
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Sheets("May").Select
    Cells.Select
    Application.CutCopyMode = False
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Sheets("Jun").Select
    Cells.Select
    Application.CutCopyMode = False
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Sheets("Jul").Select
    Cells.Select
    Application.CutCopyMode = False
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Sheets("Aug").Select
    Cells.Select
    Application.CutCopyMode = False
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Sheets("Sep").Select
    Cells.Select
    Application.CutCopyMode = False
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Sheets("Oct").Select
    Cells.Select
    Application.CutCopyMode = False
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Sheets("Nov").Select
    Cells.Select
    Application.CutCopyMode = False
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Sheets("Dec").Select
    Cells.Select
    Application.CutCopyMode = False
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
End Sub
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Try this:


Code:
Sub value_test()
Dim wb As Workbook
Dim sh As Worksheet

Set wb = ThisWorkbook

For Each sh In wb.Worksheets
    sh.Activate
    sh.Cells.Select
    Selection.Copy
    Selection.PasteSpecial xlValues
Next sh
End Sub
 
Upvote 0
Dear Lewiy, no need to activate and select
Code:
Sub value_test()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Sheets
    ws.Cells.Copy
    ws.Cells.PasteSpecial xlPasteValues
    Application.CutCopyMode = False
Next
End Sub

Edit for workbooks:
Code:
Sub value_test()
Dim ws As Worksheet, wb As Workbook
'use these lines if you open all books to loop at them and remove set wb= ...
Set wb = ThisWorkbook
'For Each wb In Application.Workbooks
    For Each ws In wb.Sheets
        ws.Cells.Copy
        ws.Cells.PasteSpecial xlPasteValues
        Application.CutCopyMode = False
    Next ws
'Next wb
End Sub
 
Upvote 0
Hi
Paste the following codes in the macro window ( Alt F8)
Code:
For a = 1 to sheets.count
Sheets(a).Select 
    Cells.Select 
    Application.CutCopyMode = False 
    Selection.Copy 
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ 
        :=False, Transpose:=False 
Msgbox "values from sheet " & worksheets(a).Name & "  copied"
next a
Run the macro. Delete message box (MsgBox - line) if you don't need it. If this works satisfactorily, I can introduce one more loop to cover all worksbooks.
Ravi
 
Upvote 0
Thank you for the code(s)... I was able to run the marco and it pasted in the workbook(s). Again, Thanks guys!!!
 
Upvote 0
I would need help with my code in the matter of Paste Special - Values. How can I change my code below to copy and paste value!?

code:
Sheets("Sheet1").Cells(i, "E").Copy Destination:=Sheets("Sheet2").Range("B" & Rows.Count).End(xlUp).Offset(1)
 
Upvote 0

Forum statistics

Threads
1,214,586
Messages
6,120,402
Members
448,958
Latest member
Hat4Life

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top