+ Reply to Thread
Results 1 to 4 of 4

Convert a text file to a unique list of words.

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    04-11-2011
    Location
    Columbus, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    325

    Convert a text file to a unique list of words.

    Hello,

    I am trying to create an excel program that will let the user select a text file and automatically convert the file into a list of unique words in excel. My biggest issue is reading one word at a time. Does anyone know how I might do this?

    Thank you,
    Last edited by 111StepsAhead; 09-17-2013 at 07:52 AM.

  2. #2
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Convert a text file to a unique list of words.

    you can try using Split function. read a line of text from the text file and use something like this
    stringArray = Split(lineOfText," ")
    For i = 0 to UBound(stringArray)
        MsgBox stringArray(i)
    Next

  3. #3
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Convert a text file to a unique list of words.

    Maybe something like:
    Sub macro_1()
    Dim fs, fil, str, i
    Set fs = CreateObject("Scripting.filesystemobject")
    Set fil = fs.Opentextfile(Application.GetOpenFilename(fileFilter:="Text Files (*.txt), *.txt"))
    Do Until fil.AtEndOfStream = True
        str = Split(fil.readline)
        For Each i In str
            If Application.CountIf(Range("A1:A" & Range("A" & Rows.count).End(xlUp).Row), "=" & i) = 0 Then
                Range("A" & Rows.count).End(xlUp).Offset(1, 0) = i
            End If
        Next
    Loop
    End Sub

  4. #4
    Forum Contributor
    Join Date
    04-11-2011
    Location
    Columbus, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    325

    Re: Convert a text file to a unique list of words.

    yudlugar,

    Your code threw a bug at

    Range("A" & Rows.Count).End(xlUp).Offset(1, 0) = i
    which I got to work by changing that If statement to

    last_R = Range("A65536").end(xlUp).Row
    Range("A" & last_R + 1).Value = i
    So from here it should be easy to work with. Thank you very much and have a good day. I am going to mark this thread as solved now.

+ 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. Import text file into Excel and using a loop to count unique words within the text
    By mrgriff21 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-24-2013, 03:17 PM
  2. Replies: 1
    Last Post: 04-04-2012, 07:15 PM
  3. Create a list of unique words from txt files
    By AdamDay in forum Excel General
    Replies: 1
    Last Post: 11-28-2007, 02:29 PM
  4. Convert numbers (numerals) to words (text)
    By Yard Sale in forum Excel General
    Replies: 3
    Last Post: 07-13-2006, 03:45 AM
  5. Convert numbers (numerals) to words (text)
    By Yard Sale in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-06-2006, 07:00 AM

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