LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Insert "/" into cells that contain data, using a macro

On Wed, 13 Feb 2008 11:11:01 -0800, garfieldmark00
wrote:

That's exactly what I needed. Many thanks Ron


You're welcome. Glad to help. Thanks for the feedback.

Note that the macro does not check that you have a valid entry. It will work
on any string where 5 digits are preceded by two or more letters or digits (or
underscores).

It would be trivial to change the code to ensure it works only on valid
entries, but more information on what constitutes a valid entry would be
required to do that.

For example, if the ONLY characters in the cell were two initial letters,
without regard to case, followed by 10 digits, then:

=========================
Sub InsertSlash()
Dim c As Range
Dim re As Object
Set re = CreateObject("vbscript.regexp")
re.Pattern = "(^[A-Za-z]{2})(\d{5})(\d{5})$"
For Each c In Selection
c.Value = re.Replace(c.Value, "$1/$2/$3")
Next c
End Sub
=========================

would process valid entries, and leave invalid entries unchanged.

You could also set conditions such as the relevant string being case sensitive;
being found anywhere within the cell; and you could set results to be just the
relevant processed string; an unprocessed string; an error message if the
pattern is not found; etc.

With all these permutations, I kept it pretty simple for an initial trial.
--ron


 
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
How do I "insert copied cells"? used to be "alt i e" still work Inserter Excel Worksheet Functions 1 February 14th 09 10:06 PM
Macro to concatenate into "B1" B2 thru B"x" based on new data in "Col A" Dennis Excel Discussion (Misc queries) 0 July 17th 06 02:38 PM
Insert "-" in text "1234567890" to have a output like this"123-456-7890" Alwyn Excel Discussion (Misc queries) 3 October 25th 05 11:36 PM
Insert 19 cells "Shift to the right" if cell contains "-" robertjtucker[_4_] Excel Programming 5 July 25th 05 04:20 PM
Adding "New" "Insert" "Delete" into a workbook to change from data 1 to data 2 etc Bob Reynolds[_2_] Excel Programming 0 March 4th 04 08:52 PM


All times are GMT +1. The time now is 03:38 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"