I just want to mention I am taking a VBA class right now and I am pretty terrible at it.
We have a homework problem that we need to import text from a text file and then loop through the text and make a count of all of the words within the text. The output will then be put in an Excel sheet with column A being the word and column B being the count. Variables already came defined which you can see in the attachment. Any help would be appreciated. I've been looking at this for a while and I just don't find VBA programming very intuitive.
Here is the starter code...
Sub ImportTextFile()
Dim fileName As Variant ' array will hold the file name or names to import
Dim i As Integer ' counter for loops
Dim j As Integer ' counter for loops
Dim dataLine As String ' string to hold a single line of text from file
Dim lineCount As Integer
Dim arrWords() As String ' array that will hold the contents of the text file
Dim arrWordSummary() As String ' array to hold summary words
Dim arrWordCount() As Integer ' array to hold counts of summary words
Dim isFound As Boolean ' for flipping the boolean
''<<<<Your code below. Feel free to add additional variables, if needed.>>>>
'Clears contents
With Range("A1:B1")
Range(.Offset(0, 0), .End(xlDown)).EntireColumn.Clear
End With
'open file
fileName = Application.GetOpenFilename
Open fileName For Input As #1
Line Input #1, dataLine
Close
Like I said, the variables were already defined and I wrote the clear contents and the open file part myself. I understand that the Open fileName command is only bringing in the first line of the text file and adding that to the string dataLine. I was trying to do the problem with only one line of text to see if I could understand it, but I haven't had any luck. Attached is the original Excel file and text file.
Thanks in advance.
Bookmarks