Formula pulls in date incorrectly - help please!

HR_Excel_User

New Member
Joined
Sep 17, 2019
Messages
4
Hey everyone!

I used this formula to add spaces after my text as I am working on a file upload where each field must be a certain length (see formula below):

='Sheet2'!D5&REPT(" ",16-LEN('Sheet2'!D5))

I have the above formula pulling from a different sheet so I wondered if that was causing the error. No matter how I format the date on either spread sheet it pulls as follows (see below):

The date on sheet2 is: 19981008 (the file requires the date as YYYYMMDD), but the above formula pulls in the date as: 3607. I'm currently stuck. I need the field to remain 16 characters so I don't want to mess with the above formula too much. Unless there's something I can add to the formula to tell it to pull the data a certain way?

Any help would be GREATLY appreciated!

Thanks in advance,

HR
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Try=TEXT(Sheet2!D5,"YYYYMMDD ")

I suspect you're actually seeing 36076 as that's the number of days from 1 Jan 1900 to 8th October 1998, which is how Excel holds dates internally.
 
Upvote 0
Try

=TEXT(Sheet2!D5,"yyyymmdd")&REPT(" ",16-LEN(TEXT(Sheet2!D5,"yyyymmdd")))

Edit: Actually, because we are formatting the date to 8 characters, this should do

=TEXT(Sheet2!D5,"yyyymmdd")&REPT(" ",8)

Edit again: Ah - I think Toadstool had it in the first place but the extra spaces have been eliminated by the forum software ;)

=TEXT(Sheet2!D5,"yyyymmdd        ") <- 8 spaces here
 
Last edited:
Upvote 0
Try

=TEXT(Sheet2!D5,"yyyymmdd")&REPT(" ",16-LEN(TEXT(Sheet2!D5,"yyyymmdd")))

Edit: Actually, because we are formatting the date to 8 characters, this should do

=TEXT(Sheet2!D5,"yyyymmdd")&REPT(" ",8)

Edit again: Ah - I think Toadstool had it in the first place but the extra spaces have been eliminated by the forum software ;)

=TEXT(Sheet2!D5,"yyyymmdd ") <- 8 spaces here

Thank you both so much for the quick response! The formula posted worked perfectly. I look forward to learning and contributing when possible on this forum! :)
 
Upvote 0
Edit again: Ah - I think Toadstool had it in the first place but the extra spaces have been eliminated by the forum software ;)
=TEXT(Sheet2!D5,"yyyymmdd ") <- 8 spaces here

Grrr! Yes, that forum software beat me again.

Code:
=TEXT(Sheet2!D5,"YYYYMMDD        ")
 
Upvote 0
Thank you both so much for the quick response! The formula posted worked perfectly. I look forward to learning and contributing when possible on this forum! :)
No problem. Glad you got a successful outcome.

BTW, "Welcome to the MrExcel board!"

@Toadstool
You can also overcome the issue of lost spaces in the forum by using repeated   instead of repeated normal spaces
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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