Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hey, Im a beginner in excel.
So, I've made a macro that opens up multiple workbooks, copies the data from the first sheet in each workbook opened and then pastes this data back into the first sheet of the master excel book. Each time the data is copied from each workbook it opens, the data needs to be pasted underneath the data that was pasted previously. Anywho, I made a macro that works but it is hardcoded - i need it to be dynamic so i can add more data later without it been overwritten by the previous pastings. Could someone make my macro dynamic by adding the vars i need and the amended code? My attempt: Sub ImportData() ' ' ImportData Macro ' ' Variables Dim lngCount As Long ' Turn Off Screen Updater Application.ScreenUpdating = False 'Opens the file dialog box With Application.FileDialog(msoFileDialogOpen) .InitialFileName = sPath .Title = sTitle .Filters.Add "Excel Files", "*.xls" .AllowMultiSelect = True If .Show = -1 Then ' Open the files to extract the data from For lngCount = 1 To .SelectedItems.Count Workbooks.Open .SelectedItems(lngCount) Next lngCount End If End With ' Start below table header - where pasting the data into the cells begins' Range("A2").Select ' The files have been opened and now extracting the data to the Master Book (Data) Worksheet; from the Workbook x (Sheet1) (Hard Coded - make this dynamic) ' Select the first of x workbooks to pull data from' Windows("Workbook 1.xls").Activate ' Then selects the Data Range and copies the data in the worksheet of' Range("A1:E26").Select Range("E26").Activate Selection.Copy ' Finally, pasting the copied data into the Master file on the Data Sheet' Windows("Master Book.xlsm").Activate ActiveSheet.Paste ' Finishing by selecting the empty cell below the pasted data in the Data worksheet in the Master Book" Selection.End(xlDown).Select Range("A28").Select < needs a loop here ' Then the process starts again for x files" Windows("Workbook 2.xls").Activate Range("A1:E23").Select Range("E23").Activate Application.CutCopyMode = False Selection.Copy Windows("Master Book.xlsm").Activate ActiveSheet.Paste Selection.End(xlDown).Select Range("A51").Select 'Close all inactive workbooks - needs hardcoding' Windows("Workbook 1.xls").Activate ActiveWindow.Close Windows("Workbook 2.xls").Activate ActiveWindow.Close End Sub Thanks, np. |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Making condition dynamic? | Excel Discussion (Misc queries) | |||
Making a dynamic list?! | Excel Discussion (Misc queries) | |||
Making print range dynamic in macro | Excel Programming | |||
making autofill range dynamic | Excel Programming | |||
Making a Dynamic List in Listbox | Excel Programming |