Solved

Value pasting to wrong workbook

Posted on 2011-03-23
6
273 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
6 Comments
 
LVL 41

Expert Comment

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

ThisWorkbook.Range("C15")

Dvae
0
 
LVL 41

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:pari123
pari123 earned 166 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 85

Accepted Solution

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

Assisted Solution

by:dlmille
dlmille earned 167 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now