VBA Convert Format "D/M" to text only

30136353

Board Regular
Joined
Aug 14, 2019
Messages
105
Hi Guys,

I have a bunch of dates which are actually address numbers, in order to vie them correctly I format them to "d/m", which shows the correct number. How I can then remove the date aspect out of the numer and keep the value of the cell "d/m", Example:

43620 is the value of the cell, date = 04/06/2019. This cells should actually be 4/6 ( An address number ), so I format it to "d/m" to show this, but some of my later validation is failing because the value is still 43620... I have it written in a code but not sure how to convert it to text only keeping the original format.

VBA Code:
    For Each C1 In Range("B2:D200")
    If C1 > 2000 Then
    C1.NumberFormat = "d/m"
    End If
    Next C1
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Code:
For Each C1 In Range("B2:D200")
If C1 > 2000 Then
C1.NumberFormat = "@"
C1.value = Format(C1,"d/m")
End If
Next C1
 
Upvote 0
How about
VBA Code:
    If c1 > 2000 Then
    c1.NumberFormat = "@"
    c1.Value = Format(c1, "d/m")
    End If
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,731
Members
448,987
Latest member
marion_davis

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