Solved

Trying to copy a value from 1 worksheet to another

Posted on 2013-11-15
2
418 Views
Last Modified: 2013-11-15
I have the following sub routine that is trying to copy a data cell from one worksheet to another…

Sub Copy_Data()
Dim DataString As String

  Application.ScreenUpdating = False
  DataString = Worksheets("Data").Range("E2:E2").Value

  Worksheets("Data").Range("E2:E2").Select
 Selection.Copy
  Worksheets("DRA Summary").Range("F5:F5").Select
  Selection.Paste
 
  Application.ScreenUpdating = True

End Sub


When the statement below is executed…
Worksheets("Data").Range("E2:E2").Select

This error occurs…
Run-time error '1004':
Select method of Range class failed.

I am trying to copy the data in cell E2 from the worksheet named “Data” to
Cell F5 in the worksheet named “DRA Summary”

Can anyone help with this or suggest a better way of accomplishing this data copy?

Thanks.
0
Comment
Question by:tesla764
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 35

Accepted Solution

by:
mvidas earned 500 total points
ID: 39651959
Hi Tesla,

You can avoid the select issue by simply applying the .Copy to the actual range object rather than the selection range object:
  Worksheets("Data").Range("E2").Copy
  Worksheets("DRA Summary").Range("F5").Paste

Open in new window


Another option to do that is to use the Destination argument of the .copy method:
Worksheets("Data").Range("E2").Copy Destination:=Worksheets("DRA Summary").Range("F5")

Open in new window


You could also just move the inner value from one cell to the other:
Worksheets("DRA Summary").Range("F5").Value = Worksheets("Data").Range("E2").Value

Open in new window

Many ways to do similar things :)
Matt
0
 

Author Closing Comment

by:tesla764
ID: 39651973
Thanks Matt. That works great. I am taking this assignment one elementry step at a time. Very good so far. On to the next step.
Thanks for your help.
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

733 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