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. #2
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,401
    Rep Power
    10
    Check the attachment. I have modified the position of the hidden columns.
    Code:
    Sub Export_DATA()
    
        Worksheets("Backlog-Raw Data").Range("J9:Q355").ClearContents
        With Application.FileDialog(msoFileDialogFilePicker)
            .AllowMultiSelect = False
            .ButtonName = "Open Raw Data"
            .Filters.Clear
            .Filters.Add "Excel Files", "*.csv"
            .Filters.Add "CSV File", "*.csv"
            .Title = "File Save As"
            .Show
            If .SelectedItems.Count Then
                strFileSelected = .SelectedItems(1)
            Else
                MsgBox "Cancelled by user!"
                Exit Sub 'Ideally, should exit from the bottom of the sub-routine.
            End If
        End With
        fncFileSelected = strFileSelected
        'Need a code here that will lookup the contect of the file being opened and will copy and paste them the Book1.xlsm
        With Workbooks.Open(Filename:=fncFileSelected, ReadOnly:=True)
            .Sheets(1).Cells(1).End(xlToRight).Offset(, 2).Resize(, 8).Value = ThisWorkbook.Worksheets("Backlog-Raw Data").Range("J8:Q8").Value
            .Sheets(1).Cells(1).CurrentRegion.AdvancedFilter Action:=xlFilterCopy, CopyToRange:=.Sheets(1).Cells(1).End(xlToRight).Offset(, 2).CurrentRegion, Unique:=False
            With .Sheets(1).Cells(1).End(xlToRight).Offset(, 2).CurrentRegion
                ThisWorkbook.Worksheets("Backlog-Raw Data").Range("J8:Q8").Resize(.Rows.Count, .Columns.Count).Value = .Value
            End With
            Workbooks(.Name).Close 0
        End With
        
    End Sub
    Attached Files Attached Files
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

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
  •