Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 465
Default Find and replace consecutive numbers



Hi All

I have two columns J and K of text and numbers.

I need to find numbers down from 50 followed by a full stop

(50. , 49. , 48. , 47. Etc)

and replace with

<p50 , <p49 , and so on.

No full stop in the replace string.

I did manage to do this long-hand , replacing each one by one , only for
Excel to tell me that my procedure was now too long.

Can someone help with some neat VBA to do this? I'm grateful for any
help on this.




Best Wishes


Colin

  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
CLR CLR is offline
external usenet poster
 
Posts: 594
Default Find and replace consecutive numbers

Using a copy of your data.........try just sorting to get them all together,
then highlight them and do Exit Replace, and replace the period, with
nothing, leave the box empty, then ReplaceAll........

If it is necessary to return to the original sorting, the before doing the
above, use a helper column to put sequentioal numbers in and after the above
procedure, sort on the new helper column, then delete it if deisred.

Vaya con Dios,
Chuck, CABGx3




"Colin Hayes" wrote in message
...


Hi All

I have two columns J and K of text and numbers.

I need to find numbers down from 50 followed by a full stop

(50. , 49. , 48. , 47. Etc)

and replace with

<p50 , <p49 , and so on.

No full stop in the replace string.

I did manage to do this long-hand , replacing each one by one , only for
Excel to tell me that my procedure was now too long.

Can someone help with some neat VBA to do this? I'm grateful for any
help on this.




Best Wishes


Colin



  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 694
Default Find and replace consecutive numbers

Colin

Try this code, using the selection for the range.

Sub ReplaceNumbers()
Dim i As Long
For i = 50 To 1 Step -1
Selection.Replace What:=i & ".", _
Replacement:="<p" & i, LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, _
SearchFormat:=False, ReplaceFormat:=False
Next i
End Sub

--
Hope this helps
Martin Fishlock, Bangkok, Thailand
Please do not forget to rate this reply.


"Colin Hayes" wrote:



Hi All

I have two columns J and K of text and numbers.

I need to find numbers down from 50 followed by a full stop

(50. , 49. , 48. , 47. Etc)

and replace with

<p50 , <p49 , and so on.

No full stop in the replace string.

I did manage to do this long-hand , replacing each one by one , only for
Excel to tell me that my procedure was now too long.

Can someone help with some neat VBA to do this? I'm grateful for any
help on this.




Best Wishes


Colin


  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,651
Default Find and replace consecutive numbers

On Mon, 25 Dec 2006 23:25:47 +0000, Colin Hayes
wrote:



Hi All

I have two columns J and K of text and numbers.

I need to find numbers down from 50 followed by a full stop

(50. , 49. , 48. , 47. Etc)

and replace with

<p50 , <p49 , and so on.

No full stop in the replace string.

I did manage to do this long-hand , replacing each one by one , only for
Excel to tell me that my procedure was now too long.

Can someone help with some neat VBA to do this? I'm grateful for any
help on this.




Best Wishes


Colin


What does your data really look like? In other words, what, exactly is in the
cell and is it formatted as text or as a number?

Or do you have comma separated values in the cells as you show in your example?
--ron
  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 465
Default Find and replace consecutive numbers

In article , Martin
Fishlock writes
Colin

Try this code, using the selection for the range.

Sub ReplaceNumbers()
Dim i As Long
For i = 50 To 1 Step -1
Selection.Replace What:=i & ".", _
Replacement:="<p" & i, LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, _
SearchFormat:=False, ReplaceFormat:=False
Next i
End Sub


Hi Martin

Yes , that's fixed it - thanks! Hooray!

My macro is not running out of space now as it's such a neat piece of
code.

It's brought up a related issue though - to do with formatting marks.
Because I'm pasting text to excel , I'm finding that the text has all
sorts of format characters (returns , paragraph marks etc). I've tried
all sorts of search and replace.

Is there any way of running a command to strip these all out , leaving
nice clean text? Or some sort of copy and paste? I know this can be done
in Word , but don't see a way in Excel.

Hope you can help.



Best Wishes


Colin





  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 694
Default Find and replace consecutive numbers

Colin,

You can try text to columns on the data menu.
Otherwise it is a matter of removing the witespace .

This can be done with VBA where you read lines of data and transform it. It
really depends on, as Ron said, what your data or file looks like. I assume
that you are trying to make some type of HTML page with the <p.

--
Hope this helps
Martin Fishlock, Bangkok, Thailand
Please do not forget to rate this reply.


"Colin Hayes" wrote:

In article , Martin
Fishlock writes
Colin

Try this code, using the selection for the range.

Sub ReplaceNumbers()
Dim i As Long
For i = 50 To 1 Step -1
Selection.Replace What:=i & ".", _
Replacement:="<p" & i, LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, _
SearchFormat:=False, ReplaceFormat:=False
Next i
End Sub


Hi Martin

Yes , that's fixed it - thanks! Hooray!

My macro is not running out of space now as it's such a neat piece of
code.

It's brought up a related issue though - to do with formatting marks.
Because I'm pasting text to excel , I'm finding that the text has all
sorts of format characters (returns , paragraph marks etc). I've tried
all sorts of search and replace.

Is there any way of running a command to strip these all out , leaving
nice clean text? Or some sort of copy and paste? I know this can be done
in Word , but don't see a way in Excel.

Hope you can help.



Best Wishes


Colin




  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 465
Default Find and replace consecutive numbers

In article , Martin
Fishlock writes
Colin,

You can try text to columns on the data menu.
Otherwise it is a matter of removing the witespace .

This can be done with VBA where you read lines of data and transform it. It
really depends on, as Ron said, what your data or file looks like. I assume
that you are trying to make some type of HTML page with the <p.



Hi Martin

Well it's the usual compendium , I'm afraid. Carriage returns ,
paragraph marks of all descriptions - many not even visible. It's a real
headache. I was hoping there was a simple remove-all procedure I could
build into the VBA. Oh well.


BTW in the coding you wrote :

Sub ReplaceNumbers()
Dim i As Long
For i = 50 To 1 Step -1
Selection.Replace What:=i & ".", _
Replacement:="<p" & i, LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, _
SearchFormat:=False, ReplaceFormat:=False
Next i
End Sub


This works perfectly for me , but I was wondering if it was possible to
have an either / or element in the selection.replace line.

At the moment it's checking to see if the number is followed by a full
stop , and then replacing with <p and the number.

Could this be modified so that


if the number is followed by a full stop

OR

the number is followed by a space


then replace this <p and the number?


I hope that makes sense. I'm grateful for any help on this.



Best Wishes


Colin

Reply
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
find and replace jason2444 Excel Discussion (Misc queries) 1 November 17th 06 04:13 PM
Find and replace numbers using a formula michelplantz Excel Worksheet Functions 6 November 6th 06 03:13 PM
How to cancel a find & replace command "midstream"? Matt from GVA Excel Worksheet Functions 4 September 4th 06 05:47 PM
Macro: Find and replace Bertie Excel Discussion (Misc queries) 1 May 29th 06 02:01 PM
Find nth occurrence and replace with ":" marlea Excel Worksheet Functions 4 October 5th 05 10:43 PM


All times are GMT +1. The time now is 06:05 AM.

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"