Results 1 to 3 of 3

Thread: VBA Macro To Open A File And Extract Data From Specific Columns

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Junior Member
    Join Date
    Oct 2014
    Posts
    26
    Rep Power
    0

    Lightbulb VBA Macro To Open A File And Extract Data From Specific Columns

    Hello All,

    I'm trying to make my workbook more flexible and trying not to depend on a fixed file path that's why i'm trying to use a combination of msoFileDialogFilePicker and lookup function but having a hard time making the code work.

    Can we use msoFileDialogFilePicker and lookup function in one macro to open a particular file and copy and paste the data to a workbook?

    The file that I need to open is the "output.csv" (csv file location varies also the number of columns but column labels are fixed) the code should copy and paste the data to "Book1.xlsm".

    Book1.xlsm columns
    Date Opened
    SR # Owner
    Severity
    Status
    Substatus
    Client Id
    User Updated On


    output.csv columns that need to be copied
    Date Opened
    SR # Owner
    Severity
    Status
    Substatus
    Client Id
    User Updated On



    Code:
    Sub Export_DATA()
    On Error GoTo noselect
    
    
    Dim Export As FileDialog
    Set Export = Application.FileDialog(msoFileDialogFilePicker)
      Export.AllowMultiSelect = False
      Export.ButtonName = "Open Raw Data"
      Export.Filters.Clear
      Export.Filters.Add "Excel Files", "*.csv"
      Export.Filters.Add "CSV File", "*.csv"
      Export.Title = "File Save As"
      If Export.Show = True Then
        fncFileSelected = fd.SelectedItems(1)
      End If
        
    'Need a code here that will lookup the contect of the file being opened and will copy and paste them the Book1.xlsm
        
        
      Range("U2") = fncFileSelected 'U2 cell will capture the path of the selected file
      Workbooks.Open (fncFileSelected)
    
    noselect:
    Exit Sub
    
      
    End Sub


    Thank you in advanced for your help.. any assistance will be very much appreciated
    Attached Files Attached Files
    Last edited by jeremiah_j2k; 12-09-2014 at 08:42 AM.

Similar Threads

  1. Macro To Browse Select File And Import Specific Data
    By violetpedal in forum Excel Help
    Replies: 4
    Last Post: 07-17-2013, 07:19 AM
  2. Replies: 3
    Last Post: 06-10-2013, 06:12 PM
  3. Replies: 6
    Last Post: 06-01-2013, 03:24 PM
  4. Macro to copy data in specific Columns
    By Howardc in forum Excel Help
    Replies: 0
    Last Post: 04-19-2013, 10:42 AM
  5. Excel VBA Macro To Open A File Through Browse Dialog Box
    By Safal Shrestha in forum Excel Help
    Replies: 2
    Last Post: 04-05-2013, 12:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •