Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-18-2018, 03:19 PM
Robert Kay Robert Kay is offline Code to find numerical string + space throughout document  & replace them with Comma Windows 10 Code to find numerical string + space throughout document  & replace them with Comma Office 2016
Novice
Code to find numerical string + space throughout document  & replace them with Comma
 
Join Date: Feb 2018
Location: Australia
Posts: 4
Robert Kay is on a distinguished road
Default Code to find numerical string + space throughout document & replace them with Comma

I am new to Word Macros. I am assisting a local historical society by scanning old electoral rolls for the area, performing OCR and then copying the data into excel tables so the data can be searched electronically.
The OCR process produces a .txt file which I then open in Word 16 so I can clean it up and comma delineate the fields of data.
The entries are:


Roll Number (space) Surname, Forenames, Address, electoral district,gender followed by a carriage return (paragraph mark).
My problem is to incorporate a sub routine (maybe not the correct technical term) to place a comma after the Roll Number which is a number between 1 and 99,999.
I have tried to use the find and replace function, (which I use to get rid of unwanted spaces and errors when the OCR program identifies . (periods) as commas.
I note the street address usually contains numbers as does the Electoral District.

Any assistance would be appreciated in formulating the appropriate code.
Reply With Quote
  #2  
Old 02-19-2018, 12:08 AM
macropod's Avatar
macropod macropod is offline Code to find numerical string + space throughout document  & replace them with Comma Windows 7 64bit Code to find numerical string + space throughout document  & replace them with Comma Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try a wildcard Find/Replace, where:
Find = ([^13^l,][0-9]{1,})^32
Replace = \1,^32
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 02-19-2018, 11:08 PM
Robert Kay Robert Kay is offline Code to find numerical string + space throughout document  & replace them with Comma Windows 10 Code to find numerical string + space throughout document  & replace them with Comma Office 2016
Novice
Code to find numerical string + space throughout document  & replace them with Comma
 
Join Date: Feb 2018
Location: Australia
Posts: 4
Robert Kay is on a distinguished road
Default Code to find Numerical string etc

Thanks for your reply Paul. I am afraid your code doesn't work. As I understand it:
The "find" expression translates ^13 is code for the paragraph break - I don't understand the expression or function ^| - or is that a lower case L?.
I assume the [0-9]{1,} is to find a numerical string between zero and nine. What is the function of the numeral one in curly brackets? I gather the expression ^32 represents a space.
My understanding of the "replace" function is that it replaces the first element in the find expression (i.e. the \1) with a space. I don't want a space, I need a comma after the number represented by the numerical string. The numerical string can be any number (i.e. set of numerals comprising a number, between 1 and 99999. The numbers above 1000 are not comma delineated.

The following text is an example of the original document:

641 Beard, Ernest Noel, 31 Tennyson st., S.8, analyst, M
642 Beard, Suzanne Louise, 31 Tennyson st., S.8, sales; F
643 Beasley, Howitt, 72 Beaumaris pde., S.21, foreman, M
644 Beasley, Joyce Ivy, 18 Victory st., S.8, mechanic, F
645 Beaton, Flora Janet, 44 Sims st., S.8, home duties, F

I want the result of the macro to produce

641,Beard, Ernest Noel, 31 Tennyson st., S.8,,analyst, M
642,Beard, Suzanne Louise, 31 Tennyson st., S.8, sales; F
643,Beasley, Howitt, 72 Beaumaris pde., S.21, foreman, M
644,Beasley, Joyce Ivy, 18 Victory st., S.8, mechanic, F
645,Beaton, Flora Janet, 44 Sims st., S.8, home duties, F

Your advice would be appreciated
Reply With Quote
  #4  
Old 02-19-2018, 11:31 PM
macropod's Avatar
macropod macropod is offline Code to find numerical string + space throughout document  & replace them with Comma Windows 7 64bit Code to find numerical string + space throughout document  & replace them with Comma Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

The wildcard Find/Replace works for me with your sample data. Did you check the 'use wildcards' option?

FWIW the Find expression finds any of a paragraph break, line break or comma followed by a number then a space. The Replace expression simply inserts a comma after the number.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 02-20-2018, 05:47 PM
Robert Kay Robert Kay is offline Code to find numerical string + space throughout document  & replace them with Comma Windows 10 Code to find numerical string + space throughout document  & replace them with Comma Office 2016
Novice
Code to find numerical string + space throughout document  & replace them with Comma
 
Join Date: Feb 2018
Location: Australia
Posts: 4
Robert Kay is on a distinguished road
Default

Paul,
Once again thank you for your prompt response. You are correct, I did not activate the wildcards option. Your code actually created a space after the comma but I resolved this by deleting the following ^32.
I "roughly" follow the code generated in the macro but would appreciate any pointers to a programming guide that explains the process in a little more detail. That is onr that does not cost an arm and a leg!
Many thanks for your prompt and most helpful assistance.
Cheers
Robert Kay
Reply With Quote
  #6  
Old 02-20-2018, 07:04 PM
macropod's Avatar
macropod macropod is offline Code to find numerical string + space throughout document  & replace them with Comma Windows 7 64bit Code to find numerical string + space throughout document  & replace them with Comma Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

The F/R expression I posted would not add a space - it will only preserve whatever space(s) were already there. It's also not a macro; it's just a wildcard Find/Replace.

For an outline of Word's wildcard Find/Replace expressions, see: https://support.office.com/en-us/art...4-7708c6c779b7, especially the discussions concerning wildcards and regular expressions.
See also: https://wordmvp.com/FAQs/General/UsingWildcards.htm
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 02-21-2018, 04:41 PM
Robert Kay Robert Kay is offline Code to find numerical string + space throughout document  & replace them with Comma Windows 10 Code to find numerical string + space throughout document  & replace them with Comma Office 2016
Novice
Code to find numerical string + space throughout document  & replace them with Comma
 
Join Date: Feb 2018
Location: Australia
Posts: 4
Robert Kay is on a distinguished road
Default Code to find numerical string + space throughout document & replace them with Comma

Paul

Thank you for your response. I have recorded the Find and Replace routine as a macro.

Thanks also for the suggested links - they are much appreciated.

Cheers

Robert Kay
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Code to find numerical string + space throughout document  & replace them with Comma Find & Replace text in Field Code across multiple documents RPM7 Word VBA 6 05-12-2017 12:58 AM
Code to find numerical string + space throughout document  & replace them with Comma Find and Replace with space cheech1981 Word 3 03-29-2017 02:33 PM
How to do multiple find and replace in string. PRA007 Word VBA 2 01-06-2016 09:10 PM
Code to find numerical string + space throughout document  & replace them with Comma Find and replace a string of text errtu Word 1 01-31-2013 02:09 PM
Code to find numerical string + space throughout document  & replace them with Comma Bad view when using Find and Find & Replace - Word places found string on top line paulkaye Word 4 12-06-2011 11:05 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:35 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft