Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Value pasting to wrong workbook

Posted on 2011-03-23
6
Medium Priority
?
280 Views
Last Modified: 2012-05-11
I have a workbook that inserts the time to cell C15. However when I have another workbook open the time is inserted to cell C15 of the active workbook. How to I prevent this from occurring?
Snippet from code that puts the data and time in the C15 cell 
of the Active workbook  when I need it in
ThisWorkbookSheets(1).Range C15

Set TimeC = range("C15")
   TimeC = TimeC.Value
   range("B15").Value = Left(Trim(range("B15").Value), 12)
   MyData.SetText ""
   MyData.PutInClipboard
   TimeC.Value = Date & ":" & Time

Open in new window

0
Comment
Question by:llawrenceg
[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
6 Comments
 
LVL 42

Expert Comment

by:dlmille
ID: 35200124
Try referring to the range like ths:

ThisWorkbook.Range("C15")

Dvae
0
 
LVL 42

Expert Comment

by:dlmille
ID: 35200142
Set TimeC = ThisWorkbook.Range("C15") 'where the code is running
TimeC = TimeC.Value

Now that TimeC is pointed to the right workbook, the rest of your code should be fine.

Dave
0
 
LVL 20

Assisted Solution

by:Ardhendu Sarangi
Ardhendu Sarangi earned 664 total points
ID: 35200162
whats the name of the target workbook?


you can use somthing like this...replace target with the actual name of the excel file

Workbooks("Target").Activate
Set TimeC = range("C15")
   TimeC = TimeC.Value
   range("B15").Value = Left(Trim(range("B15").Value), 12)
   MyData.SetText ""
   MyData.PutInClipboard
   TimeC.Value = Date & ":" & Time

Open in new window

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 85

Accepted Solution

by:
Rory Archibald earned 668 total points
ID: 35200285
Set TimeC = ThisWorkbook.Sheets(1).range("C15")  
0
 
LVL 42

Assisted Solution

by:dlmille
dlmille earned 668 total points
ID: 35200813
I forgot the sheets part

Lol
0
 

Author Closing Comment

by:llawrenceg
ID: 35200988
Great Guys , I needed to know where to put it and you  told me.
Thanks Works perfectly
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

721 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