Link to home
Start Free TrialLog in
Avatar of llawrenceg
llawrencegFlag for United States of America

asked on

Value pasting to wrong workbook

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

Avatar of dlmille
dlmille
Flag of United States of America image

Try referring to the range like ths:

ThisWorkbook.Range("C15")

Dvae
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
SOLUTION
Avatar of Ardhendu Sarangi
Ardhendu Sarangi
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of llawrenceg

ASKER

Great Guys , I needed to know where to put it and you  told me.
Thanks Works perfectly