-
VBA, Excel-Copy value only of cells from one worksheet to another worksheet
Goal: Copy the value only (not formulas) of a range of cells (B2:Y34) from Worksheet 6 to Worksheet7
Existing VBA code:
Sub Copy_Data()
Application.ScreenUpdating = False
Worksheets("Sheet6").Range("B2:Y34").Value = ActiveSheet("Sheet7").Range("B2:Y34").Value
Application.ScreenUpdating = True
End Sub
If anyone would be able to point me in the right direction I would greatly appreciate it. I am having trouble pinpointing and resolving the gliche.
-
I recorded a macro and did the steps you wanted. This is what I got:
Code:
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 3/30/2009 by Ronald A Weller
'
Range("B2:Y34").Select
Selection.Copy
Sheets("Sheet5").Select
Range("B2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End Sub
-
I tested your routine also and with a few changes it will work also; but because you are not doing a copy and paste you can't use undo to cancel the copy.
Here is the modified version of your routine:
Code:
Sub Copy_Data()
Application.ScreenUpdating = False
Worksheets("Sheet7").Range("B2:Y34").Value = Worksheets("Sheet6").Range("B2:Y34").Value
Application.ScreenUpdating = True
End Sub
Notice here I changed your ActiveWorksheet to Worksheets, The ActiveWorksheet object is reference to the currently Active worksheet not a collection of worksheets, so ActiveWorksheet("Name") won't work.
Also you had your object references backwords; which would have overitten the values in worksheet 6 with the ones in worksheet 7. So I changed the object references so that the worksheet 7 object was assigned the values from the worksheet 6 object. Not the other way around.
Similar Threads
-
By thegeeber in forum VB Classic
Replies: 11
Last Post: 04-03-2009, 11:52 PM
-
By damien_carr in forum VB Classic
Replies: 0
Last Post: 01-29-2009, 05:29 PM
-
By Hack in forum VB Classic
Replies: 0
Last Post: 01-06-2009, 10:44 AM
-
By slimasian in forum .NET
Replies: 0
Last Post: 05-15-2008, 04:24 PM
-
Replies: 3
Last Post: 06-25-2007, 07:30 AM
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|