+ Reply to Thread
Results 1 to 14 of 14

Import text file

Hybrid View

  1. #1
    Registered User
    Join Date
    09-27-2009
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Import text file

    Quote Originally Posted by norhaya View Post
    Hi

    Below is my code, please review and comments, however, I am still not able to call up the part number and description. Any ideas?

    Sub ImportText()

    Dim i As Long, n As Long

    Dim tmpString As String
    Dim tmpAUC As String 'AUC = Average Unit Cost
    Dim Fname As String
    Dim tmpCAT As String 'CAT = Category
    Dim tmpPICK As String ' PICK = Picking Sequence
    Dim tmpUOM As String ' UOM = Unit of Measure
    Dim tmpPN As String ' PN = Part Number
    Dim tmpDesc As String ' Desc = Description
    Dim tmpQOH As Variant ' QOH = Qty on Hand


    Fname = "C:\Import\Accpac.txt"
    Open Fname For Input As #1
    Cells.Clear

    Range("A1:I1").Value = Array("Part No", "Desc", "Date Last Shipment", "Date Last Receipt", "Average Unit Cost", "UOM", "Qty On Hand", "Location", "Remarks")
    tmpPN1 = InStr(tmpString, "") & InStr(tmpString, " ") & InStr(tmpString, "category")
    i = 2
    n = 1
    Do While Not EOF(1)
    Line Input #1, tmpString
    If (InStr(tmpString, "Category")) > 0 Then
    tmpCAT = Right$(tmpString, 12)
    Sheet1.Range("C" & i).Value = tmpCAT

    ElseIf (InStr(tmpString, "Picking")) > 0 Then
    tmpPICK = Right$(tmpString, 12)
    Sheet1.Range("D" & i).Value = tmpPICK
    ElseIf (InStr(tmpString, "Average unit cost")) > 0 Then
    tmpUOM = Right$(tmpString, 16)
    tmpAUC = Mid(tmpString, 44, 14)
    Sheet1.Range("F" & i).Value = Trim(tmpUOM)
    Sheet1.Range("E" & i).Value = tmpAUC

    i = i + 1

    End If

    Loop
    Close #1
    Worksheets("Sheet1").Range("A1:I1").Columns.AutoFit

    End Sub
    Hi Bigmack

    After going thru all the text, if I could join the line before line with "catergory" so it would be 1 string, then I could parse it easily. Can you guide/show me on the code? If this works then I can complete this task.

    Appreciate your assistance.

    Thanks, norhaya

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Import text file

    CODE tags, please, not QUOTE tags, and only around code.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    05-20-2009
    Location
    NY
    MS-Off Ver
    Excel 2003
    Posts
    57

    Lightbulb Re: Import text file

    Norhaya, please follow the rules--simply edit your post and use <code> tags otherwise I cannot even post a hint for you.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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