Creating Simple Function, getting "Compile error: Expected: )"

Maxbot

New Member
Joined
Dec 21, 2017
Messages
1
Hello, I am completely green when it comes to making my own functions. Could someone tell me what I'm doing wrong here? I am sorry I was not able to find a relevant previous post.

--------------------------------------------------------------------------------------------------------------------------------

Function mDate(yyyymmdd1 As String)


'Converts date strings from "yyyymmdd" format to "mm/dd/yyyy" format
'Function will only work on strings with a length of 8 characters


mDate = Format(DATE(LEFT(yyyymmdd1,4),RIGHT(LEFT(yyyymmdd1,6),2),RIGHT(yyyymmdd1,2)), "Short Date")


End Function

--------------------------------------------------------------------------------------------------------------------------------

Thanks,
Max
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Welcome to the Board!

Use "DateSerial" instead of "Date", i.e.
Code:
Function mDate(yyyymmdd1 As String)

'Converts date strings from "yyyymmdd" format to "mm/dd/yyyy" format
'Function will only work on strings with a length of 8 characters

mDate = Format(DateSerial(Left(yyyymmdd1, 4), Right(Left(yyyymmdd1, 6), 2), Right(yyyymmdd1, 2)), "Short Date")

End Function
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,021
Latest member
Mohamed Magdi Tawfiq Emam

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