LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Help making this macro dynamic :)

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Making condition dynamic? aposatsk Excel Discussion (Misc queries) 3 August 16th 06 01:43 PM
Making a dynamic list?! mayerc Excel Discussion (Misc queries) 2 June 15th 06 03:47 PM
Making print range dynamic in macro Newbie dumbo Excel Programming 1 December 14th 05 10:47 AM
making autofill range dynamic sonang Excel Programming 0 September 1st 04 10:59 PM
Making a Dynamic List in Listbox MikeM[_4_] Excel Programming 2 December 16th 03 04:16 PM


All times are GMT +1. The time now is 04:37 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"