COPY DATA from WORKBOOK to WORKBOOK

acakoning

New Member
Joined
Jun 16, 2014
Messages
21
Hi all, so I have already computed a MACRO which takes a look into a particular FOLDER and counts the number of workbooks, then, my SHOWPROGBAR MACRO will create the required number of sheets (NUMBER_OF_SHEETS) to match the number of workbooks in the FOLDER. Now I would like the MACRO to open each workbook and COPY the data from sheet "00" into sheet "1", close that workbook and open the next, COPY the data from sheet "00" into sheet "2", etc. How can i do this? Here is my code so far:
Code:
Sub CombineSheets()
    Dim sPath As String
    Dim sFname As String
    Dim Count As Integer
    Dim wBk As Workbook
    Dim wSht As Variant
    Dim NUMBER_OF_WORKBOOKS As Integer
    
    Application.EnableEvents = False
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    
    Call Delete
    
    sPath = InputBox("Enter a full path to workbooks")
    If sPath = "" Then Exit Sub
    ChDir sPath
    sFname = InputBox("Enter a filename pattern (for example 140630*) ")
    sFname = Dir(sPath & "\" & sFname & ".xl*", vbNormal)
    
    Do While sFname <> ""
        Count = Count + 1
         sFname = Dir()
    Loop
    
        Range("NUMBER_OF_SHEETS").Value = Count
    
    Call ShowProgIndicator
    
    ActiveWorkbook.Save
    Application.EnableEvents = True
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
    
End Sub
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
The reason for doing this in this particular way is because I don't want to copy the Name Manager or any related stuff which is present in the workbooks.
 
Upvote 0
So I have isolated the copy pasting part for better understanding: THIS IS NOT WORKING! why does it not understand were to copy it? The MACRO is in the file identified as Master:
Code:
Sub COPYPASTE()
    Dim sPath As String
    Dim sFname As String
    Dim wBk As Workbook
    Dim Master As String
    Dim wSht As Variant
    Dim wSW As Variant
    
    Application.EnableEvents = False
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    sPath = InputBox("Enter a full path to workbooks")
    ChDir sPath
    sFname = InputBox("Enter a filename pattern (for example 140630*) ")
    sFname = Dir(sPath & "\" & sFname & ".xl*", vbNormal)
    wSht = "00"
    Do While sFname <> ""
        Set wBk = Workbooks.Open(sFname)
        Windows(sFname).Activate
        Range("A1:CP148").Select
        
            Selection = Selection.Value
            Selection.Copy
        
    Master = "FC Template_Operations_Cons_v2.1.xlsm"
    wSW = x + 1
                
            Workbooks(sFname).Sheets(wSht).Range("A1:CP148").Copy
            Workbooks(Master).Sheets(wSW).Range("A1:CP148").PasteSpecial Paste:=xlPasteValues
            
        wBk.Close False
        sFname = Dir()
    Loop
    ActiveWorkbook.Save
    Application.EnableEvents = True
    Application.DisplayAlerts = True
    
    Application.ScreenUpdating = True
 
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,102
Messages
6,128,849
Members
449,471
Latest member
lachbee

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top