Excel VBA

I have a Template Workbook that is my main file.

the workbook name is   MyTemp.xlsm   it has only two sheets Sheet("Main") and Sheet("Data")
now every week, i download another excel workbook that its extenstion is .xls and it has two sheet("Other") and Sheet("Data") .  

i need a macro that when both of my files are open and there are no other files open, the macro copies everything from downloaded file Sheet("Data") and pastes it into the workbook MyTemp.xlsm Sheet("Data")  

that's it.

thanks.
LVL 6
FloraAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Phillip BurtonDirector, Practice Manager and Computing ConsultantCommented:
Do you want formulas to copy across, or just the values?
0
FloraAuthor Commented:
just values
0
Rob HensonFinance AnalystCommented:
Will the columns in both data sheets be the same?

You could setup a Data Connection between the two files. When source Data sheet is updated, refresh link in Destination workbook and new data will be populated.

Thanks
Rob H
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

FloraAuthor Commented:
the column of both are not the same always.

what i want is that i do not need the existing data in workbook MyTemp.xlsm   Sheet("Data").  the macro should delete all data first from MyTemp.xlsm   Sheet("Data") before pasting new data from other downloaded workbook.
0
Phillip BurtonDirector, Practice Manager and Computing ConsultantCommented:
Make sure you have saved MyTemp.xlsm before running, as it cannot be undone. This code should be launched from your spreadsheet.

Sub CopyFromTempToTemp()
    Sheets("Data").Select
    Selection.Copy
    Windows("MyTemp.xlsm").Activate
    Sheets("Data").Select
    Cells.Select
    Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
        xlNone, SkipBlanks:=False, Transpose:=False
    Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rob HensonFinance AnalystCommented:
I assume the formulas in Main are referencing particular columns. If the columns are not the same, how are you managing the columns moving?

Or, have you misunderstood the question??? I would expect the number of rows in each column to change but the position of the columns to stay the same. If this is the case then doing a Data Connection would do as you require, it would remove existing data and replace with new.

Thanks
Rob H
0
FloraAuthor Commented:
@Phillip Burton
thank you Philip. just a question, i need to run the code from MyTemp.xlsm  . do i understand correctly that i would put your written code into MyTemp.xlsm and then run it?  becuase MyTemp.xlsm is my main file that i want to launch the macro from.   wouldn't there by any possiblity that if i run the code form MyTemp.xlsm it activetes other workbook copies the data then activates MyTemp.xlsm and pastes it in MyTemp.xlsm Data sheet.
0
FloraAuthor Commented:
@Rob Henson
thank you.  the number of columns and rows are increased and sometimes decreased each time i download the new data.
0
Rob HensonFinance AnalystCommented:
Looks like Philips routine will pretty much do what you want but I note there are a couple of steps missing:

Sub CopyFromTempToTemp()
    'Select Temp Data File
    Windows("TempFile.xls").Activate
    Sheets("Data").Select
    'Copy cells from temp data
    Cells.Copy
    Windows("MyTemp.xlsm").Activate
    Sheets("Data").Select
    Cells.Select
    Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
        xlNone, SkipBlanks:=False, Transpose:=False
    Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
End Sub

Open in new window

0
Phillip BurtonDirector, Practice Manager and Computing ConsultantCommented:
I would put the code in MyTemp.xlsm.

Activate the other workbook (which name I don't know).

Run the code from the other workbook (it will be called MyTemp.xlsm!CopyFromTemptoTemp

>> wouldn't there by any possiblity that if i run the code form MyTemp.xlsm it activetes other workbook copies the data then activates MyTemp.xlsm and pastes it in MyTemp.xlsm Data sheet

I thought that is what you wanted. But my code is designed to be stored in MyTemp.xlsm, but run from the other spreadsheet. So you have just opened the other spreadsheet, and then run the code.
0
Rob HensonFinance AnalystCommented:
For the changing columns, how are you handling the ongoing calculations, presumably on the Main sheet?

Thanks
Rob H
0
FloraAuthor Commented:
thanks Philip

you are the star.

that is exactly what i needed.
0
Rob HensonFinance AnalystCommented:
I think maybe you should have accepted Phillip's solution.

You can request moderator attention to change it.

Thanks
Rob
0
FloraAuthor Commented:
Yes. i made a mistake. i meant to click on the Philips comment. i will ask mod to change it.

thanks Rob for pointing this.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.