none
Open File Explorer Code RRS feed

  • Question

  • I am trying to write a code that allows me to open file explorer and import a .csv file, but I only need the data from cells A57 and B57 down until there is no more data. I would need that data imported to the active macro into cells A31 and B31.

    Thanks for the help!

    Tuesday, August 7, 2018 12:33 PM

All replies

  • See if this does what you want:

    Sub ImportData()
        Dim strFile As String
        Dim wbk As Workbook
        Dim lngLastRow As Long
        strFile = Application.GetOpenFilename(FileFilter:="CSV files (*.csv),*.csv")
        If strFile = "False" Then
            Beep
            Exit Sub
        End If
        Application.ScreenUpdating = False
        Set wbk = Workbooks.Open(Filename:=strFile)
        With wbk.Worksheets(1)
            lngLastRow = .Range("A:B").Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
            .Range("A57:B" & lngLastRow).Copy Destination:=ThisWorkbook.Worksheets(1).Range("A31")
        End With
        wbk.Close SaveChanges:=False
        Application.ScreenUpdating = True
    End Sub


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Tuesday, August 7, 2018 1:17 PM