issue with numbers and dot in cell

michlimes

Board Regular
Joined
May 20, 2008
Messages
66
I have some vba macro, which should insert month and year with mask mmm.yyyy (i.e. 008.2014).

When macro is trying to put value "008.2014" into cell, excel recognizes it as a number and change value into number 8.2014. What's more, regional settings in windows has other decimal place -> comma.

How can I stop recognizing such a string as a number in Excel? I've tried str() in macro, but it hasn't helped...
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Can you share the code?
If I had the code I could experiment and see if I can help.
 
Upvote 0
There are many solutions, but a couple that come to mind:
1. You could change the format of the destination column to Text before the insert takes place. Depending how you are inserting, the strings will remain strings.
2. You could probably make use of a formula like =TEXT(A2,"mm.YYYY") in your macro
 
Last edited:
Upvote 0
Code:
Sub StringDate()

Dim StrDate As String

StrDate = "008.2014"
StrDate = Mid(StrDate, 2, 2) & "/" & Right(StrDate, 4)
StrDate = CDate(StrDate)

'The result in the cell will be Aug.2014
ActiveCell.Value = Format(StrDate, "mmm.yyyy")

End Sub
 
Upvote 0
Try:
Code:
Sub test()
ActiveCell.NumberFormat = "@"
ActiveCell.Value = "008.2014"
End Sub
 
Upvote 0

Forum statistics

Threads
1,225,072
Messages
6,182,695
Members
453,132
Latest member
nsnodgrass73

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top