PDA

View Full Version : SOLVED: WildCards - need to insert extra TAB



StingRay
03-28-2007, 07:57 AM
I am aligning my data in WORD, in preparation for exporting to EXCEL.
Records are separated by paragraphs, fields are separated by tabs. Fields contain both letters and numbers, mixed.

Some records (paragraphs) contain 3 fields (2 tabs), others contain 4 fields (3 tabs).

For records (paragraphs) which contain only 3 fields (2 tabs), in order to align data, I need to move data from field# 3 into a new field# 4. In other words, create a new (blank) field in the #3 position.

I have tried various combinations of WildCards, using Find & Replace, but no luck.

Would greatly appreciate your assistance!

mdmackillop
03-28-2007, 09:07 AM
Hi Singray,
Welcome to VBAX
I think we need to see a sample. Zip your file and post it using Manage Attachments in the Go Advanced section.
Regards
MD

StingRay
03-28-2007, 03:26 PM
Hello MD -

Thanks for the response. Here is a sample of my data. As you can see, these are library books in the format TITLE-AUTHOR-PUBLISHER-CALL#. However, in some cases the PUBLISHER field was omitted by the data source. Thus, in those cases, I need to create an empty field in order to properly align the data for export to EXCEL. I will be processing the data in blocks of 100 books.

Would a VBA solution perhaps be easier/better?

Thanks again -

StingRay

Note - The book titles are hyperlinks.

Early Virginia immigrants, 1623-1666 Greer, George Cabell. Genealogical Pub. Co., 1978. 929.3755 G859Ea
Emigration to other states from Southside Virginia. Elliott, Katherine B. (Katherine Blackwell) R929.3755 EL58E
Fayette Co WV marriages, 1830-1870 Haga, Pauline A. Mountain Press, [198-?] 929.37547 H1201F 1980
The Germanna record. Memorial Foundation of the Germanna Colonies in Virginia. R929.1755 G317

mdmackillop
03-28-2007, 03:45 PM
Can you please zip and post this in a Word document, complete with tabs etc. so we can see exactly what we're dealing with.

StingRay
03-28-2007, 04:02 PM
MD -

Please see data in attached ZIP file

Thanks -

StingRay

mdmackillop
03-28-2007, 05:14 PM
I had some problem with your paragraphs; they were not being recognised, hence the extra sub

Sub AddTabs()
MakeParas
For Each p In ActiveDocument.Paragraphs
chk = UBound(Split(p, Chr(9)))
If chk = 2 Then
Set rng = p.Range
pos = InStr(1, rng, Chr(9))
pos = InStr(pos + 1, rng, Chr(9))
rng.Collapse wdCollapseStart
rng.MoveEnd Unit:=wdCharacter, Count:=pos
rng.InsertAfter Chr(9)
End If
Next
End Sub

Sub MakeParas()
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = Chr(13)
.Replacement.Text = "^p"
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub

StingRay
03-28-2007, 06:24 PM
MD -

Thanks much!

RE the unrecognized paragraphs: I may have caused that problem. The data I sent you had already been through the Find/Replace mill at least 6 times. In the process, I may have improperly used some ^9's or ^13's.

No big deal - I'm just grateful to have some code that works!

Best Regards -

StingRay