Home |
Search |
Today's Posts |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How do I "insert copied cells"? used to be "alt i e" still work | Excel Worksheet Functions | |||
Macro to concatenate into "B1" B2 thru B"x" based on new data in "Col A" | Excel Discussion (Misc queries) | |||
Insert "-" in text "1234567890" to have a output like this"123-456-7890" | Excel Discussion (Misc queries) | |||
Insert 19 cells "Shift to the right" if cell contains "-" | Excel Programming | |||
Adding "New" "Insert" "Delete" into a workbook to change from data 1 to data 2 etc | Excel Programming |