LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #17   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Efficient storage

Hi Robert,

Am Sun, 10 May 2015 21:05:38 +0200 schrieb Claus Busch:

Sub Test2()


better:


sorry but you get an error if you have no numbers in your text.

Try:

Sub Test2()
'New 2015-05-09 C.B.
'Revised 2015-05-10 C.B.
Dim strPath As String
Dim strFN As String
Dim objReadFile As Object, myDic As Object, objFSO As Object, re As
Object
Dim strText As String
Dim varText() As Variant, varOut As Variant, varTmp() As Variant
Dim i As Long, LRow As Long, n As Long
Dim ptrn, Match, Matches
Dim FERow As Range

Application.ScreenUpdating = False

'Modify path and file name
strPath = "C:\Users\Claus\Desktop\"
strFN = "Test.txt"

Set myDic = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set re = CreateObject("vbscript.regexp")

'Opens the text file and read the text into a string
Set objReadFile = objFSO.opentextfile(strPath & strFN)

Do While objReadFile.atendofstream < True
strText = strText & objReadFile.readline & " "
Loop
objReadFile.Close

'Handles special cases like I'll, it's and so on
'Customize it depending on your text file
strText = Replace(Replace(Replace(Replace(Replace(Replace(st rText, _
"'s ", " is "), "'ll ", " will "), "'d ", " had "), "'re ", _
" are "), "'ve ", " have "), "'m ", " am ")
strText = Application.Trim(strText)

'Separate all "words"
ptrn = "\w+"
re.Pattern = ptrn
re.IgnoreCase = False
re.Global = True
Set Matches = re.Execute(strText)
ReDim Preserve varText(Matches.Count - 1)
For Each Match In Matches
varText(n) = LCase(Match.Value)
n = n + 1
Next

'Create unique words
For i = LBound(varText) To UBound(varText)
myDic(varText(i)) = varText(i)
Next
varOut = myDic.items

'Distrubutes the words in alphabetic order to columns
Range("A1") = "Header"
Range("A2").Resize(UBound(varOut) + 1) = _
Application.Transpose(varOut)
LRow = Cells(Rows.Count, 1).End(xlUp).Row
n = 2
For i = 97 To 122
Range("A1:A" & LRow).AutoFilter Field:=1, Criteria1:="=" & Chr(i) &
"*"
If Application.Subtotal(3, Range("A:A")) 1 Then
Range("A2:A" & LRow).Copy Cells(1, n)
End If
n = n + 1
Next
n = 0
If Application.Count(Range("A:A")) 0 Then
For i = LBound(varOut) To UBound(varOut)
If IsNumeric(varOut(i)) Then
ReDim Preserve varTmp(n)
varTmp(n) = varOut(i)
n = n + 1
End If
Next
End If
ActiveSheet.AutoFilterMode = False
If n 0 Then
Range("AB1").Resize(n) = Application.Transpose(varTmp)
End If

Columns("A").Delete
Columns("A:AA").AutoFit
Application.ScreenUpdating = True
End Sub


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
XML Data Storage Rookie_User Excel Discussion (Misc queries) 0 June 30th 08 07:11 PM
Persistent Storage for Add-Ins ? Brian Herbert Withun Excel Programming 2 January 25th 08 02:24 PM
cell value storage Leo Rod Excel Programming 2 August 30th 07 03:47 PM
Data Storage gregory.barrett Excel Discussion (Misc queries) 3 March 30th 06 10:23 PM
Variable Storage gti_jobert[_10_] Excel Programming 3 February 8th 06 11:28 AM


All times are GMT +1. The time now is 05:19 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"