How to strip dashes out of numbers in a variable

M

mikeburg

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
 
B

Bernie Deitrick

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

iainking

Bernie said:
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
 
B

Bob Phillips

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

--

HTH

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

Bernie Deitrick

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
 
I

iainking

Bernie said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top