Insert "/" into cells that contain data, using a macro
That's exactly what I needed. Many thanks Ron
"Ron Rosenfeld" wrote:
On Sun, 10 Feb 2008 09:48:01 -0800, garfieldmark00
wrote:
I need to insert a "/" symbol into multiple cells which already contain data.
For example: the cell already contains 2 letters and 10 digits and I need to
insert the / symbol after the 2 letters and then again after the next 5
digits, so the data changes from aa########## to aa/#####/#####. All the
cells are in one column so it's simple to get a macro to select the column,
but I don't know how to insert characters. Any ideas?
I'm using Excel 2007.
Using regular expressions, something like:
==========================
Option Explicit
Sub InsertSlash()
Dim c As Range
Dim re As Object
Set re = CreateObject("vbscript.regexp")
re.Pattern = "(\w{2})(\d{5})"
For Each c In Selection
c.Value = re.Replace(c.Value, "$1/$2/")
Next c
End Sub
=================================
--ron
|