Question regarding copying data from a selected WB to another.

espcn

New Member
Joined
Jun 10, 2013
Messages
2
Hello everyone, I am quite new to excel and have tried making a simple macro that just copies all of the available data from a workbook and pastes it in another. I have looked at information available on the internet and combining data from multiple sources I have reached the following code that does not do what I want:

Code:
Option Explicit

Sub GatherData()




Dim wbCSV   As Workbook
Dim wsMstr  As Worksheet
Dim FileToOpen As String
Dim fPath As String
Dim fCSV    As String


Application.ScreenUpdating = False
Application.EnableEvents = False
Application.DisplayAlerts = False
    
    
Set wsMstr = ThisWorkbook.Sheets("Data")


'If MsgBox("Clear the existing Data?", vbYesNo, "Clear?") _
    = vbYes Then wsMstr.UsedRange.Clear


 ' MsgBox "Please select a folder with the relevant files"
  '  Do
   '     With Application.FileDialog(msoFileDialogFolderPicker)
    '        .InitialFileName = "C:\Users\And\Desktop\MP1X"
     '       .AllowMultiSelect = False
      '      .Show
       '     If .SelectedItems.Count > 0 Then
        '        fPath = .SelectedItems(1) & "\"
         '       Exit Do
          '  Else
           '     If MsgBox("No folder has been chosen, do you wish to abort?", _
            '        vbYesNo) = vbYes Then Exit Sub
            'End If
       ' End With
    'Loop
FileToOpen = Application.GetOpenFilename("Excel Files (*.xls), *.xls, All Files (*.*), *.*", , "Look for your file below", "XLS", False)
'Application.GetOpenFilename ("Text Files (*.csv), *.csv")
If FileToOpen <> False Then
        Set wbCSV = Workbooks.Open(FileToOpen & fCSV)
      'insert col A and add CSV name
        Columns(1).Insert xlShiftToRight
        Columns(1).SpecialCells(xlBlanks).Value = ActiveSheet.Name
      'copy date into master sheet and close source file
        ActiveSheet.UsedRange.Copy wsMstr.Range("A" & Rows.Count).End(xlUp).Offset(1)
        wbCSV.Close False
      'ready next CSV
        fCSV = Dir
 End If
    
ErrorExit:        'Cleanup
    ActiveSheet.Columns.AutoFit
    Application.DisplayAlerts = True         'turn system alerts back on
    Application.EnableEvents = True          'turn other macros back on
    Application.ScreenUpdating = True        'refreshes the screen
End Sub
I have tried a search on the forums but I could not find anything that I could apply with my limited understanding. Any indications on how to proceed would be greatly appreciated. Thank you all for your assistance on this matter.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
What do you want it to do and how exactly is it not doing what you want?
 
Upvote 0
I would like it to show a text message asking which file to select and then copy it the data contained withing without opening the file itself. After trying to modify the macros found online to suit what I am trying to do, quite a few errors cropped up which I could not get to the bottom of.
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

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