+ Reply to Thread
Results 1 to 7 of 7

How to strip dashes out of numbers in a variable

  1. #1
    Forum Contributor
    Join Date
    06-23-2005
    Posts
    253

    How to strip dashes out of numbers in a variable

    How do you strip out dashes, convert numers to a text string, & assign it to a variable from the following?

    monthendate=6-30-05

    monthendname=monthendate (need the monthendname to be 63005)

    Thank so very much.

    mikeburg

  2. #2
    Bernie Deitrick
    Guest

    Re: How to strip dashes out of numbers in a variable

    mike (who apparently doesn't like capital letters)

    Dim MonthEndDate As Date
    Dim MonthEndName As String
    MonthEndDate = DateValue("6-30-05")
    MonthEndName = CStr(Format(MonthEndDate, "mdyy"))
    MsgBox MonthEndName

    HTH,
    Bernie
    MS Excel MVP


    "mikeburg" <[email protected]> wrote in message
    news:[email protected]...
    >
    > How do you strip out dashes, convert numers to a text string, & assign
    > it to a variable from the following?
    >
    > monthendate=6-30-05
    >
    > monthendname=monthendate (need the monthendname to be 63005)
    >
    > Thank so very much.
    >
    > mikeburg
    >
    >
    > --
    > mikeburg
    > ------------------------------------------------------------------------
    > mikeburg's Profile: http://www.excelforum.com/member.php...o&userid=24581
    > View this thread: http://www.excelforum.com/showthread...hreadid=387171
    >




  3. #3

    Re: How to strip dashes out of numbers in a variable



    Bernie Deitrick wrote:
    > mike (who apparently doesn't like capital letters)
    >
    > Dim MonthEndDate As Date
    > Dim MonthEndName As String
    > MonthEndDate = DateValue("6-30-05")
    > MonthEndName = CStr(Format(MonthEndDate, "mdyy"))
    > MsgBox MonthEndName
    >
    > HTH,
    > Bernie
    > MS Excel MVP
    >


    I think I must be being pretty dumb, but doesn't Format return a
    string? Why use CStr? Plus, CStr rather idioticaly adds a space to
    the left of the string, so if you do need to use it, you should use:
    MonthEndName = LTrim(CStr(Format(MonthEndDate, "mdyy")))

    Iain


  4. #4
    Bob Phillips
    Guest

    Re: How to strip dashes out of numbers in a variable

    myVar = Application.Substitute("6-30-05","-","")

    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "mikeburg" <[email protected]> wrote in
    message news:[email protected]...
    >
    > How do you strip out dashes, convert numers to a text string, & assign
    > it to a variable from the following?
    >
    > monthendate=6-30-05
    >
    > monthendname=monthendate (need the monthendname to be 63005)
    >
    > Thank so very much.
    >
    > mikeburg
    >
    >
    > --
    > mikeburg
    > ------------------------------------------------------------------------
    > mikeburg's Profile:

    http://www.excelforum.com/member.php...o&userid=24581
    > View this thread: http://www.excelforum.com/showthread...hreadid=387171
    >




  5. #5
    Bernie Deitrick
    Guest

    Re: How to strip dashes out of numbers in a variable

    You're right that I didn't need it - but CStr doesn't add a space:

    Dim myVal As Long
    myVal = 2314
    MsgBox Len(myVal) = Len(CStr(myVal))

    Could you post code that shows that it does?

    HTH,
    Bernie
    MS Excel MVP


    <[email protected]> wrote in message news:[email protected]...
    >
    >
    > Bernie Deitrick wrote:
    >> mike (who apparently doesn't like capital letters)
    >>
    >> Dim MonthEndDate As Date
    >> Dim MonthEndName As String
    >> MonthEndDate = DateValue("6-30-05")
    >> MonthEndName = CStr(Format(MonthEndDate, "mdyy"))
    >> MsgBox MonthEndName
    >>
    >> HTH,
    >> Bernie
    >> MS Excel MVP
    >>

    >
    > I think I must be being pretty dumb, but doesn't Format return a
    > string? Why use CStr? Plus, CStr rather idioticaly adds a space to
    > the left of the string, so if you do need to use it, you should use:
    > MonthEndName = LTrim(CStr(Format(MonthEndDate, "mdyy")))
    >
    > Iain
    >




  6. #6
    Forum Contributor
    Join Date
    06-23-2005
    Posts
    253

    You all help a lot & I appreciate it!

    Thank you very much.

    You all help a lot & I appreciate it!

    mikeburg

  7. #7

    Re: How to strip dashes out of numbers in a variable



    Bernie Deitrick wrote:
    > You're right that I didn't need it - but CStr doesn't add a space:
    >
    > Dim myVal As Long
    > myVal = 2314
    > MsgBox Len(myVal) = Len(CStr(myVal))
    >
    > Could you post code that shows that it does?
    >
    > HTH,
    > Bernie
    > MS Excel MVP
    >


    No, I was right the first time - I'm being pretty dumb. Str adds a
    leading space, not CStr. My bad.

    Iain


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1