View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Gord Dibben Gord Dibben is offline
external usenet poster
 
Posts: 22,906
Default Removing dashes in entire column using VBA

sup

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
On Error GoTo enditall
Application.EnableEvents = False
If Target.Cells.Column = 1 Then ''1 is column A''
Target.Cells.Replace What:="-", _
Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
End If
enditall:
Application.EnableEvents = True
End Sub

Copy to a worksheet module(right-click on sheet tab and "View Code") and paste
in there.

Gord Dibben Excel MVP

On Wed, 4 Feb 2004 21:48:15 -0600, sup191
wrote:

I posted here earlier and got very quick, helpful answers and thought I
might try it one more time... I'm trying to format a whole column so
that when data is pasted in it, all the dashes are removed. For
example, I want anything pasted into column K to have the dashes
removed automatically. I know I could just do a replace on column K,
but I'm trying to get this spreadsheet entirely automated so the people
who are using it don't have to do that extra step. My job consists of
TONS of copying and pasting and I was hoping for an automatic answer.
The data could be any alpha or number string. The only thing that can
pop in are dashes which screw up the program I'm importing this
spreadsheet into.

So, "qwert-123" would autoformat to "qwerty123".

Is this possible without copying a substitute function to every cell in
the column?

Thanks in advance for any help solving this puzzle. ;)


---
Message posted from http://www.ExcelForum.com/