Moving to newly Saved Workbook

D

DonW

I have a prob where I can't add data from a worksheet I'm working with and a
new workbook I just created.

original file in E:\
then
ActiveWorkbook.SaveAs Filename:="E:\Archived Logs\" & lz & " Data " & mydate
& ".xls"
Windows("original_file.xls").Activate
Sheets("Data").Select
Range("A3").Activate
hdr_bus = ActiveCell.Value
ActiveCell.Cells(1, 2).Activate
hdr_time = ActiveCell.Value
Windows(lz & "Data " & mydate).Activate
'At this point I expect code to put focus on the new workbook and
start adding data, BUT IT DOESN'T
Sheets("Sheet1").Activate
Range("A1").Activate
ActiveCell.FormulaR1C1 = hdr_bus
ActiveCell.Cells(1, 2).Activate
ActiveCell.FormulaR1C1 = hdr_time

The hdr_bus and hdr_time are written to the original_file.xls, Data
worksheet, range("A3")

I don't want to copy the entire worksheet because there are other areas that
cannot be copied to the new workbook.

Can you help please??

Don
 
N

Nigel

Try this approach......

Dim wbArchive As Workbook
Dim wbOriginal As Workbook

Set wbArchive = ActiveWorkbook
wbArchive.SaveAs Filename:="E:\Archived Logs\" & lz & " Data " & mydate &
".xls"

Windows("original_file.xls").Activate
Set wbOriginal = ActiveWorkbook

With wbOriginal.Sheets("Data")
wbArchive.Sheets("Sheet1").Range("A1") = .Range("A3").Value
wbArchive.Sheets("Sheet1").Range("A2") = .Range("A4").Value
End With
 
D

DonW

Thank you Nigel, I'll give it a try.....

Don

Nigel said:
Try this approach......

Dim wbArchive As Workbook
Dim wbOriginal As Workbook

Set wbArchive = ActiveWorkbook
wbArchive.SaveAs Filename:="E:\Archived Logs\" & lz & " Data " & mydate &
".xls"

Windows("original_file.xls").Activate
Set wbOriginal = ActiveWorkbook

With wbOriginal.Sheets("Data")
wbArchive.Sheets("Sheet1").Range("A1") = .Range("A3").Value
wbArchive.Sheets("Sheet1").Range("A2") = .Range("A4").Value
End With

--

Regards,
Nigel
(e-mail address removed)
 
D

DonW

Now, Nigel, let's assume the data grows, how could I use your suggestion to
loop through, not only the header data - on row A3 in original file, but
also all of my data?

Don
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top