Pb with date format when using .Value=(Value,X)

vadius

Board Regular
Joined
Jul 5, 2011
Messages
70
Hi there,

I have two sheets and I am trying to extract the date value from one sheet to another with the below code. The problem I have is that the date I want to extract are written as a text in the cells with the following format & sentence :

"SMI® PR as of 01-07-2010"
"SMI® PR as of 02-07-2010"

etc for each day

So I computed the below code that extract the 10 right letters to get "01-07-2010". The problem I have is that the value I get in the second sheet is not a text any longer : vba/excel converts automatically into a date format dd/mm/yy , but the format is wrong. Instead of having 1st of July, 2nd of July etc.. I have 7th of January, 7th of February etc...

I tried to change the column format with mm-dd-yy but it does not work.

Have you guys any ideas on how I could get the extract values in the right date format dd-mm-yy ? I need then to sort the data in my extract by dates..

Thanks for your help

=====================================================

Sub copydate()

Dim strValue As String
Dim strCellNum As String
Dim x As String
x = 2
For i = 2 To 6000 Step 26
strCellNum = "A" & i
strValue = Worksheets("Extract").Range(strCellNum).Value
Debug.Print strValue
Worksheets("Clean").Range("A" & x).Value = Right(strValue, 10)
x = x + 1
Next

End Sub
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Use a non-ambiguous entry:
Code:
Worksheets("Clean").Range("A" & x).Value = format(CDate(Right(strValue, 10)),"dd/mmm/yy")
 
Upvote 0
Thanks it does work perfectly.
I tried somethong like .Value = Format (Right (... but I forgott the "CDate"

Anyway thanks a lot
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,849
Members
452,948
Latest member
UsmanAli786

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