Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Automatically removing hyphens from ID# or SSN.

You're welcome, Biff.

"T. Valko" wrote:

you turned .enableevents off


Yes, that's what I did. I had it in the wrong place.

Thanks, Dave!

Biff

"Dave Peterson" wrote in message
...
Pasting should fire the _change event. I'm guessing that in your testing,
you
turned .enableevents off (maybe when one test version broke). And it was
never
turned back on.

But this kind of thing worked ok for me--I wasn't sure about the
formatting,
though.

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

Dim myStr As String
Dim myCell As Range
Dim myRng As Range

Set myRng = Intersect(Me.Range("C:C"), Target)

If myRng Is Nothing Then Exit Sub

On Error Resume Next
For Each myCell In myRng.Cells 'just column C
With myCell
myStr = Replace(.Value, "-", "")
If IsNumeric(myStr) Then
.NumberFormat = String(12, "0")
Application.EnableEvents = False
.Value = myStr
Application.EnableEvents = True
End If
End With
Next myCell
On Error GoTo 0

End Sub


"T. Valko" wrote:

I tried writing an event macro to do this.

A couple of things that caused problems:

Pasting into a target cell doesn't fire the macro.

Excel insists on converting 123451234561 to scientific notation:
1.23E+11.
Setting the target format to:

Target.NumberFormat = "@"

does set the format to TEXT, however, it still displays as text 1.23E+11
not
text 123451234561. Widening the column didn't make a difference either.

I didn't save the code so I can't post it.

Biff

"Martin Fishlock" wrote in message
...
Hi Faraz:

Try this little gem. It replaces the active sheet only:

Sub hyphensconvertcolConly()
ActiveSheet.Columns("C:C").Replace _
What:="-", Replacement:="", _
LookAt:=xlPart, SearchOrder:=xlByRows, _
MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
End Sub

Merss around with
ActiveSheet.Columns("C:C").

to change different sheets or columns:

as in activeworkbook.worksheets("Sheet1").Columns("D:G") .
.....
--
Hope this helps
Martin Fishlock, Bangkok, Thailand
Please do not forget to rate this reply.


"FARAZ QURESHI" wrote:

Thanx Ed

But I have to consolidate several statements received in parts. Is
there
a
way 2 "automatically" replace the hyphens? A VBA Macro is welcomed.

"Ed Ferrero" wrote:

Hi FARAZ QURESHI,

Select the data you wish to convert. Use Edit - Replace, and
replace
"-"
with nothing.

Ed Ferrero
www.edferrero.com

I am looking forward for a macro or any other way to convert my
data:

12345-123456-1

when pasted into a column lets suppose C:C, to:

123451234561

i.e. hyphens removed automatically.
Can anyone please help?
Thanking in advance




--

Dave Peterson


--

Dave Peterson
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
Removing Non-Numeric Characters - Automatically - How? emerald Excel Discussion (Misc queries) 6 April 4th 06 08:03 PM
Copy Rows to another Sheet Automatically Tim & Holly Excel Worksheet Functions 2 March 7th 06 12:53 PM
Automatically update cells Maddoktor Excel Discussion (Misc queries) 1 December 8th 05 12:56 AM
Excel file automatically opens - More Info Lost4Now Excel Discussion (Misc queries) 2 December 4th 05 11:01 PM
Can I shut off Excel automatically removing the first 0 seingold Excel Discussion (Misc queries) 1 November 28th 05 03:03 PM


All times are GMT +1. The time now is 02:08 PM.

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"