+ Reply to Thread
Results 1 to 3 of 3

Macro command to import 2 different data sets from the same file

  1. #1
    Registered User
    Join Date
    07-07-2015
    Location
    Wash DC
    MS-Off Ver
    10
    Posts
    57

    Macro command to import 2 different data sets from the same file

    Im using excel to parse some data sets from a file... The code i am using below has me select the same file two different times .. Trying to find a way to select the file just once....
    Thanks


    Sub ACV_ImportRawACV10File()
    'needs to be on ACV10 tab
    Sheets("ACV10").Select
    Dim fn As String, x, e, n As Long
    fn = Application.GetOpenFilename("LogFiles,*.log")
    If fn = "False" Then Exit Sub
    x = Split(CreateObject("Scripting.FileSystemObject").OpenTextFile(fn).ReadAll, vbLf)
    For Each e In x
    'items need to be in quotes followed by stars
    If e Like "* start time: *" Then
    n = n + 1: Cells(n, 1) = e
    ElseIf e Like "* COMPLETED end time: *" Then
    Cells(n, 2) = e
    End If
    Next
    End Sub

    Sub ACV_ImportRawACV10_2File()
    'needs to be on ACV10_2 tab
    Sheets("ACV10_2").Select
    Dim fn As String, x, e, n As Long
    fn = Application.GetOpenFilename("LogFiles,*.log")
    If fn = "False" Then Exit Sub
    x = Split(CreateObject("Scripting.FileSystemObject").OpenTextFile(fn).ReadAll, vbLf)
    For Each e In x
    'items need to be in quotes followed by stars
    If e Like "*Total time (milliseconds) taken by job*" Then
    n = n + 1: Cells(n, 1) = e
    ElseIf e Like "*Total records processed:*" Then
    Cells(n, 2) = e
    End If
    Next
    End Sub

  2. #2
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,223

    Re: Macro command to import 2 different data sets from the same file

    Excel will not guess that the file has already been used. He needs help somehow.
    For example, in a hidden sheet (Sheet100 in the example) you will keep the paths of the files used. At the beginning of the procedure you will check if the file specified by the user is on the black list.
    Please Login or Register  to view this content.
    The second procedure probably needs to be improved in a similar way.

    Artik

  3. #3
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Macro command to import 2 different data sets from the same file

    https://www.excelforum.com/excel-pro...ml#post5423230
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 08-03-2016, 11:44 PM
  2. [SOLVED] MACRO: Store name of selected file as string w/ import data file dialog box
    By AnnieMcken in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-13-2013, 02:13 PM
  3. Macro - Import file and copy all data
    By djsouljah in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-25-2013, 05:10 AM
  4. [SOLVED] Macro - Master file to import data from another open file with variable file name
    By jdodz in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-10-2012, 10:56 PM
  5. Macro to import .CSV file data to another .xls file
    By Scottie in BKK in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-28-2012, 09:21 PM
  6. How do I import data with a macro from one file/sheet to another
    By john55 in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 11-04-2010, 03:57 AM
  7. Import Data File Macro
    By Apro_Soya in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-27-2010, 02:41 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1