Consulting

Results 1 to 2 of 2

Thread: Importing a CSV and via Userform

  1. #1
    VBAX Newbie
    Joined
    Oct 2007
    Posts
    2
    Location

    Post Importing a CSV and via Userform

    Hello. I have a few raw data files (CSV) that I would like to import into a macro I created. The macro does what it does and I have no problems with it, except proper importation.

    I use the archaic version of importing:
    [vba]Open "H:\JFadriqu\Macros\Data\102-08 at 400N.CSV" For Input As #1
    k = 0
    Do Until EOF(1)
    Input #1, t, f, x
    If t = 0 Then
    k = k + 1
    i = 2
    End If
    Worksheets(k).Cells(i, 1).Value = t
    Worksheets(k).Cells(i, 2).Value = f
    Worksheets(k).Cells(i, 3).Value = x
    Worksheets(k).Cells(i, 4).Value = k
    i = i + 1
    Loop
    Do Until EOF(1)
    i = 1
    i = i + 1
    Worksheets(1).Cells(i, 4).Value = 1
    Worksheets(2).Cells(i, 4).Value = 2
    Worksheets(3).Cells(i, 4).Value = 3
    Loop
    Close #1[/vba]

    The problem is that this only works IF the CSV data files are all numeric and start from R1-C1. Rather than changing every single CSV file, I would like for it to read starting from when the data at Time 0. The CSVs contain headers that look like this:

    {
    1 Dry 402-01 at 400N.CSV
    2
    3
    4 Created ################
    5 Exported################
    6
    7 Channels
    8 Disp Load Torque
    9
    10 Units
    11 mm NN mV V Nm
    12
    13 Movers
    14 Axial Torsion
    15
    16 Elapsed Time Torque Rotation
    17 Sec Nm deg
    18 0 -4.411 -7.54
    19 0.05 -4.321 -7.48
    ........
    }

    So the actual data I want to generate starts at R18-C1.

    Can anyone tell me the proper coding so I can fix this? I always get errors: SUBSCRIPT OUT OF RANGE if I don't edit the CSV file.




    Also in the future, I would like to be able to do an "Open Dialog box" Userform to load the CSV file rather than "OPEN... FOR INPUT".

    Any input would be greatly appreciated!

    Regards!

  2. #2
    VBAX Newbie
    Joined
    Oct 2007
    Posts
    2
    Location
    Can someone at least help through the userforms?

    thanks

Posting Permissions

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