Adjusting data in cell

AlexanderBB

Well-known Member
Joined
Jul 1, 2009
Messages
2,072
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
I formatted a column to custom 'dd mmm yyyy' which is mostly what's wanted but some of the data has year only.
So I've been entering 'dd mmm 1999'. Now I don't like it as there's too many, and having the year only is tidier.
Changing the Format to text allows the year only but changes the full formatted Date to a number.
Some values also don't have a year so "07 Apr 19?" is used.
Is there a format where I can have all those without (as someone said) having a leading apostrophe?
And I think I need to remove the value for each cell, reformat it, and reapply the value.
 
If that is correct, then this macro will change Column A ( change if necessary) to what I described above.

VBA Code:
Sub test()
Dim c As Range, s
For Each c In Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row)
If IsDate(c) And c <> "" Then
    c.NumberFormat = "dd mmm yyyy"
Else
    s = Split(c)
    If s(2) = "??" Then
        c = StrConv(s(1), vbProperCase)
    Else
        c = s(2)
    End If
End If
Next
End Sub
 
Upvote 0

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Scott, Col B would be dd mmm yyyy or however much is available from Col A.
Alex, is there a Text to column button ? The only way I know is to r-Click column, Then Format Cells - Number - Text. And I think it only works if the column (cell?) is empty.
I made the mistake of formatting Column to Custom "dd mmm yyyy" thinking it would leave anything it couldn't format as it was.
 
Upvote 0
Alex, is there a Text to column button ?
There certainly is ;)

You will find more information here >
Converting Text to Numbers or Converting Dates is more common useage but in this case we want to convert the displayed value to Text.

1707376351377.png



1707376583383.png
 

Attachments

  • 1707376414038.png
    1707376414038.png
    40.3 KB · Views: 4
Upvote 0
A "just put what I type in" category would be really useful.
It already exists - that is the "Text" option. If you format the column to cells to "Text" before you make your entries, it will always enter exactly what you type in with no conversions.
Of course, if you use that, you are then entering text entries and not date entries.
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

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