Flora Edwards
asked on
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.
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.
Do you want formulas to copy across, or just the values?
ASKER
just values
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
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
ASKER
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
ASKER
@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.
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.
ASKER
@Rob Henson
thank you. the number of columns and rows are increased and sometimes decreased each time i download the new data.
thank you. the number of columns and rows are increased and sometimes decreased each time i download the new data.
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
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!CopyFromTempto Temp
>> 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.
Activate the other workbook (which name I don't know).
Run the code from the other workbook (it will be called MyTemp.xlsm!CopyFromTempto
>> 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.
For the changing columns, how are you handling the ongoing calculations, presumably on the Main sheet?
Thanks
Rob H
Thanks
Rob H
ASKER
thanks Philip
you are the star.
that is exactly what i needed.
you are the star.
that is exactly what i needed.
I think maybe you should have accepted Phillip's solution.
You can request moderator attention to change it.
Thanks
Rob
You can request moderator attention to change it.
Thanks
Rob
ASKER
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.
thanks Rob for pointing this.