Excel VBA - Text to Date after running macro in a single Row - excel

I have several Macros running at once in a file. The output pastes unique dates from B1:Z1 on the next sheet. The dates right now are pasting as ex. 43619 instead of 6/3/2019. I have been troubleshooting this but everything I have found is a whole column instead of rows. Thanks!

To Excel a Date is a number(the number of days since 1/1/1900). The number is formatted to look like a date.
If you are just pasting the values the format is not following and as such the value is reverted to the number.
To apply the formatting just use:
Worksheet("Sheet1").Range("B1:Z1").NumberFormat = "mm/dd/yyyy"
Changing the sheet name to your desired sheet and the number format to the format desired.

Related

Date in Spreadsheet shows as number when cell format is short date

One spreadsheet in the workbook has a column of dates that appear as left justified numbers, even though the format on the column is Short Date. Cannot set the column to number format, change alignment or force any other format. When a cell is selected it shows as a date in the cell and in the formula bar, but when focus is changed, it reverts to number. How to fix this?
The spread sheet was copied from another workbook, and was apparently protected in that workbook. Thus not able to format or change anything. Ended up selecting all cells in the worksheet and pasting into a new worksheet. Able to apply changes then.

How can I dynamically reference cells containing dates in cubemember formula

I have converted my Cube Pivot table to formulas using OLAP Tools > Convert to formulas.
The column labels are dates in UK format, which is fine. The CUBEMEMBER formula is as such:
=CUBEMEMBER("Name of Cube","[Date].[Display Date].&[27/01/2017]")
This is the issue:
If i copy and paste the date 27/01/2017 in this exact format (For example), and paste it above the cell that has the CUBEMEMBER formula, i can succesfully replace the member_expression part with that cell reference in 2 ways:
One: =CUBEMEMBER("Name of Cube","[Date].[Display Date].&["&B8&"]")
Two: =CUBEMEMBER("Name of Cube",B8)
I do not want to have to copy and paste dates, then link to those cells in order for it to work. I want to be able to link to a cell that already has a date in it. The difference is that its not in the EXACT same format as cubemember. Even if i copy the formats of the date, it does not work.
Any guidance??
Dates are stored as numbers in Excel. The way to get the date as you want it is by using TEXT. With Swedish number formats in Windows the date can be shown as text by using this formula:
=TEXT(A1;"ÅÅÅÅ-MM-dd")
the "ÅÅÅÅ" part should probably be "yyyy" or "YYYY" for UK formats and could of course be "dd/MM/yyyy".

Excel 2013 How to assign dates to cells

I'd like to assign dates to cells in a planner spreadsheet I have made.
Currently, the rows are months, the columns are days of the week, and each individual cells just have a number for the day of the month.
I don't want to display the full date in the cell, just have the cell "know" what date it is representing. One use of this could be to have the current day always highlighted in a different colour when opening the spreadsheet. Is this possible in Excel?
Looking at your question, the results would require to show multiple "dates" within the cell.
For January '16 for example, you would have 4 different type of dates as January has 4 Mondays (4;11;18;25). Is this what you're looking to achieve? Otherwise it is not possible to have excel figure out a single date unless you provide it with additional references in order to come up with a result.
Enter a date into a cell. Format the cell to show the part of the date you want to see. In the screenshot, column A contains full dates in each cell. A2 and down are formatted with the custom format code shown in column C
Excel still treats the dates as the underlying full dates in formulas, even though only parts of the dates are showing in the cell.

excel date time cell being covertet to numeric and cant stop it

i have two sheets the first one to call a value from the second sheet, in the first sheet i have
=IFERROR(VLOOKUP(B2,'sheet'!B5:'sheet'!I2500,8,FALSE),"")
this works fine for all full text fields
but when i have a date time of
04/26/2013 11:27:00
it converts it to 41390.47708
if i manually edit the cell and put in an apostrophe it is fine but if i try and use a macro or another column to add the apostrophe it changes it to a number and then adds the apostrophe.
is there a way to get the formula to treat the cell as text
When you use a function like VLOOKUP it only retrieves the underlying value from the referenced cell, not the formatting (and display of date and time is achieved by formatting) - can't you just format the cell with the formula in the required format?
Right-click on the cell and choose Format Cells > Number > Custom and type this in the box
mm/dd/yyyy hh:mm:ss
If the formula might retrieve text or a date/time you can still format it that way because the text will be unaffected

Excel, change format of a date, then make ALL cells in column look the new way

I have a file where the date column is in a format I cannot make calculations, so I changed the column to another format where I can subtract dates. As usually happens with excel though, only when I double click an entry it changes to the new format.
Does anyone know how I can force all the cells in column to change to the new format, in order for my script to be able to subtract dates for the whole file?
Here is a really easy work-around:
Insert a blank column.
Change the format of the blank column to the date format that you want.
Copy the column with the dates that won't format.
Right-click on the first cell of the blank, formatted column, select Paste Special, select Paste:Values and Operation:Add. (Because the destination cells are blank, the dates will be unchanged.) Click OK.
The dates will now appear as dates.
Try this in your vbScript
objExcel.Cells(Row, Column).NumberFormat = "#0.00"
If you just want to do this via VBA, you can use something like this:
Range("C1:C100").NumberFormat = Range("B2").NumberFormat
The example above just changes the format for cells C1-C100 to whatever the format is in B2.
Update:
I noticed you said that the format is working fine, but dispalys as #######. This typically happens when the column is not wide enough to show the whole value, so resizing it manually or using something like the belwo should fix your issue:
Columns("C:C").EntireColumn.AutoFit
You may also want to try =Datevalue() in an adjacent column. My experience in these types of situation is that Excel doesn't understand that your entries are dates. They are text, and will not change to date simply on a format change. Alternatively you can try text to columns to do the conversion.

Resources