0
votes

I'm new to VBA and have been reading quite a bit about it lately, though I've ran into a small issue which I can't seem to find the an answer to.

I have a spread sheet that I need to format into a certain amount of columns, pulling data from one column and reformatting it into another.

One of these columns needs to include an week-end date that the report was submitted on - the date is in a cell (N10) and looks like this:

Week: 2011 36:02 Oct 11 - 08 Oct 11

So I've sliced that cell and entered it into another cell (C14) with this bit of code:

 Range("C14") = "=Right($N$10, 9)"

I'm able to get the portion of the string "08 Oct 11" but cannot get it into a m/d/yyyy format. This is the portion of the code I'm using to format to a date:

 Columns("C:C").NumberFormat = "m/d/yyyy"

I'm imagine that this cell needs to be formatted more in order to then format as a date, but I'm not sure where to start.

Thank you

1

1 Answers

2
votes

The Right function will return a string, you need to convert it to a date. There's a variety of ways you could do that, one way could be to use the Value function:

Range("C14") = "=Value(Right($N$10, 9))"

This will give C14 the value 40824 (see this for an explanation), but once you apply your NumberFormat it will display as 10/8/2011.