change cell format within functions

amiroo

Board Regular
Joined
Dec 24, 2013
Messages
124
Office Version
  1. 2019
Platform
  1. Windows
Hi,

I wrote a function in excel vba. return value of the function is date, but function just return value of date in cell

how can I change format of cell to date (short date is preferred)

this is my code
Code:
Function Gregorian(rng As Range, Optional Mode As Boolean = False) As Date
DateArr = separate_date(rng.value)  [COLOR=#339900]' such as: 1396/02/19 (jalali date)[/COLOR]
If UBound(DateArr) <> 2 Then Gregorian = CVErr(2042)
Gregorian = Date2Value(rng.value, "J") - 466699  [COLOR=#339900]' such as: 509806 - 466699 => return 43107[/COLOR]
End Function
 
yes it shows but don't group it and you can't use date filters either. take a look at this pic:

filtering_date_filter.png

True -You are right .. I am sure someone here with more knowledge of formulas will see this and provide a solution.
 
Upvote 0

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

Forum statistics

Threads
1,216,091
Messages
6,128,775
Members
449,468
Latest member
AGreen17

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