?
Solved

Trying to copy a value from 1 worksheet to another

Posted on 2013-11-15
2
Medium Priority
?
436 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 2000 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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

770 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