Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Macro doesn't work

I'm trying to paste the values of all cells in all worksheets in a workbook.
Can anyone figure out why this doesn't work for all sheets? The same
structure works for other things, so I'm confused.

Sub Paste_Value_All_Sheets()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
Cells.Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Next ws
End Sub


Thanks for any insights.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Macro doesn't work

Cells defaults to the activesheet. You have to explicitly qualify Cells
for each ws. You also can't select cells on an inactive sheet.

One way:

Dim ws As Worksheet
For Each ws in ActiveWorkbook.Worksheets
ws.Select
Cells.Select
'as original
Next ws


Better, since it doesn't require selection:

Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
With ws.UsedRange
.Value = .Value
End With
Next ws


In article ,
Alan P wrote:

I'm trying to paste the values of all cells in all worksheets in a workbook.
Can anyone figure out why this doesn't work for all sheets? The same
structure works for other things, so I'm confused.

Sub Paste_Value_All_Sheets()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
Cells.Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Next ws
End Sub


Thanks for any insights.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Macro doesn't work

Alan,

Change
Cells.Select
' to
WS.Select
WS.Cells.Select


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Alan P" wrote in message
...
I'm trying to paste the values of all cells in all worksheets
in a workbook.
Can anyone figure out why this doesn't work for all sheets?
The same
structure works for other things, so I'm confused.

Sub Paste_Value_All_Sheets()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
Cells.Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues,
Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Next ws
End Sub


Thanks for any insights.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Macro doesn't work

Chip and JE, thanks for your help. Works fine now.

"Alan P" wrote:

I'm trying to paste the values of all cells in all worksheets in a workbook.
Can anyone figure out why this doesn't work for all sheets? The same
structure works for other things, so I'm confused.

Sub Paste_Value_All_Sheets()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
Cells.Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Next ws
End Sub


Thanks for any insights.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to sum doesn't work RM270 Excel Discussion (Misc queries) 2 March 17th 10 05:55 PM
Macro to update a column in a work based on another work sheet WickerMan New Users to Excel 1 December 4th 09 12:58 PM
Macro works Macro does not work Wanna Learn Excel Discussion (Misc queries) 4 March 24th 08 12:51 PM
Macro with =SUM doesn't work leopardhawk Excel Programming 5 May 31st 05 09:27 PM
Why does the macro not work? Xanadude Excel Worksheet Functions 4 April 24th 05 09:06 PM


All times are GMT +1. The time now is 02:29 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"