Results 1 to 10 of 22

Thread: Importing a csv File to a range

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Junior Member SDruley's Avatar
    Join Date
    Nov 2012
    Posts
    23
    Rep Power
    0
    Rick,

    That was a fast open but is there a way to open the contents of the csv file into Application.Range("BANKA"). I don't have CPU time to do a cut and paste. Wow you are up early.

    Steve


    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    Last edited by DocAElstein; 06-11-2023 at 01:24 PM.

  2. #2
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    15
    Quote Originally Posted by SDruley View Post
    Rick,

    That was a fast open but is there a way to open the contents of the csv file into Application.Range("BANKA"). I don't have CPU time to do a cut and paste. Wow you are up early.
    Actually, I wasn't up early... I had not gone to sleep for the "night" yet. Based on a past message, I assume you mean BANKB, not BANKA (anyway, that is what the code below assumes). See if this code (run from the workbook with BANKB defined in it) works...
    Code:
    Sub Import_BANKA_DataFileInto_BANKB()
      Dim FileNum As Long, TotalFile As String
      FileNum = FreeFile
      Open "c:\Temp\PicassoPg.csv" For Binary As #FileNum
        TotalFile = Space(LOF(FileNum))
        Get #FileNum, , TotalFile
      Close #FileNum
      Application.ScreenUpdating = False
      With Range("BANKB").Columns(1)
        .Value = WorksheetFunction.Transpose(Split(TotalFile, vbNewLine))
        .TextToColumns Comma:=True
      End With
      Application.ScreenUpdating = True
    End Sub

  3. #3
    Junior Member SDruley's Avatar
    Join Date
    Nov 2012
    Posts
    23
    Rep Power
    0
    Rick,

    Thank you for the code to retreive the csv file and place the contents into the primary workbook. As it turns out this code took a little over 2 seconds to complete while snb's solution was .24 seconds. So I will keep your solution on creating the csv file and snb's solution for reading it.

Similar Threads

  1. Macro To Close All CSV Files
    By Howardc in forum Excel Help
    Replies: 5
    Last Post: 03-15-2014, 05:24 PM
  2. Save Excel 2010 File In CSV Format VBA
    By mag in forum Excel Help
    Replies: 7
    Last Post: 01-08-2013, 07:16 PM
  3. Macro to export sheet as CSV
    By Howardc in forum Excel Help
    Replies: 2
    Last Post: 07-25-2012, 08:59 PM
  4. Replies: 1
    Last Post: 06-02-2011, 10:38 AM
  5. Save File In CSV Format VBA
    By Raj Kumar in forum Excel Help
    Replies: 3
    Last Post: 06-01-2011, 07:22 AM

Posting Permissions

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