Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Removing hyphens
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
David McRitchie  
View profile  
 More options Feb 27 2000, 3:00 am
Newsgroups: microsoft.public.excel.programming
From: "David McRitchie" <DMcRitc...@msn.com>
Date: 2000/02/27
Subject: Re: Removing hyphens
Hi Mike,
This should remove doubled hyphens in place (macro solution),
as well as prefixed and suffixed hyphens for TEXT value
within a selected range.    Will ignore numbers like -7.
TRIM which removes spaces will be performed on all text cells
that contain at least one hyphen within the selected area.
Prior to XL97  xlCellTypeConstants might be xlConstants

Option Explicit

Sub REMXHYPS()
  'David McRitchie 2000-02-27  excel.programming
  'hyphen removals of dups, prefixed, suffixed, and trim results
  Application.ScreenUpdating = False
  Application.Calculation = xlCalculationManual   'pre XL97 xlManual
      Dim newstr As String
      Dim oldstr As String
      Dim lst As String
      Dim ix As Integer
      Dim x As String
      Dim cell As Range
  For Each cell In Selection.SpecialCells(xlCellTypeConstants, 2)
    'above limits to constants which are TEXT
    If InStr(1, cell.Value, "-") Then
      lst = "-"
      newstr = ""
      oldstr = Trim(cell.Value)
      For ix = 1 To Len(oldstr)
        x = Mid(oldstr, ix, 1)
        If x = "-" Then
          If lst <> "-" Then newstr = newstr & x
        Else
          newstr = newstr & x
        End If
        lst = Mid(oldstr, ix, 1)
      Next
      If Right(newstr, 1) = "-" Then newstr = Left(newstr, Len(newstr) - 1)
      cell.Value = Trim(newstr)
    End If
   Next
  Application.Calculation = xlCalculationAutomatic  'pre XL97 xlAutomatic
  Application.ScreenUpdating = True
End Sub

HTH,
David McRitchie,  Microsoft MVP - Excel
My Excel Pages:  http://members.aol.com/dmcritchie/excel/excel.htm

tim williams <saxif...@pacbell.net> wrote in message

news:F7mu4.453$Fl3.13264@news.pacbell.net...

> Function formatMe(stuff As String)
> stuff = Trim(stuff)
> 'remove trailing -'s
> Do While Right(stuff, 1) = "-"
> stuff = Left(stuff, Len(stuff) - 1)
> Loop

> strTemp = ""
> bFlag = False

> For n = 1 To Len(stuff)
>     If Mid(stuff, n, 1) = "-" And bFlag = False Then
>         strTemp = strTemp & Mid(stuff, n, 1)
>         bFlag = True
>     ElseIf Mid(stuff, n, 1) <> "-" Then
>         strTemp = strTemp & Mid(stuff, n, 1)
>         bFlag = False
>     End If
> Next n
> formatMe = strTemp

> End Function

> Mike Van Sydenborgh <poin...@mergetel.com> wrote in message
> news:SJku4.22993$bz2.4285542@tw12.nn.bcandid.com...
> > A file that I import into Excel, leaves hypens around the data I'm
> > interested in.
> > Some examples are:

> >   DCK-43V---
> > FS--4824--G3---
> > SWS---7224--S

> > I want one hyphen between letters like SWS-7224-S and the hypens beyond
> > letters to be removed like this: FS-4824-G3

> > The final product should appear as: DCK-43V, FS-4824-G3,
> > SWS-7224-S


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.