PC Review


Reply
 
 
Theresa
Guest
Posts: n/a
 
      5th Aug 2008
Hi:

I receive a file that contains a column of dates in a format that is not
recognized as a date: ie: 20080714. I am trying to create a macro to
insert the "/" at the required places.

Here is the code I am using:

Range("D3" & Range("E65536").End(xlUp).Row).FormulaR1C1 = Trim(Left(C3, 4)
& "/" & Mid(C3, 5, 2) & "/" & Right(C3, 2))

I want to look at the data in Column E to see how far to go, then take the
date in Column C and put it in Column D in the correct format. When I run
the macro, all I get is // with nothing else.

What am I doing wrong?

Thanks,
 
Reply With Quote
 
 
 
 
Gary''s Student
Guest
Posts: n/a
 
      5th Aug 2008
With 20080714 in cell C3, this macro will put the date in C4:

Sub theresa()
v = Range("C3").Value
yr = Left(v, 4)
mn = Mid(v, 5, 2)
dy = Right(v, 2)
Range("C4").Value = DateSerial(yr, mn, dy)
End Sub
--
Gary''s Student - gsnu200797


"Theresa" wrote:

> Hi:
>
> I receive a file that contains a column of dates in a format that is not
> recognized as a date: ie: 20080714. I am trying to create a macro to
> insert the "/" at the required places.
>
> Here is the code I am using:
>
> Range("D3" & Range("E65536").End(xlUp).Row).FormulaR1C1 = Trim(Left(C3, 4)
> & "/" & Mid(C3, 5, 2) & "/" & Right(C3, 2))
>
> I want to look at the data in Column E to see how far to go, then take the
> date in Column C and put it in Column D in the correct format. When I run
> the macro, all I get is // with nothing else.
>
> What am I doing wrong?
>
> Thanks,

 
Reply With Quote
 
Theresa
Guest
Posts: n/a
 
      5th Aug 2008
Hi Gary:

But I need it to evaluate how many rows to go down, and the dates will be
different in each row. EG: I have dates in rows C3:C30 in the 20080714
format. I need the dates to be in the 2008/07/14 format. The number of rows
will change constantly so I need to evaluate how many rows to work with.

Here is a small sample file:

Carrier Pro/Inv Date Date2 Customer
DRR CLG1510679 20080714 Gescan
DRR DAR2639057 20080714 Gescan
DRR MTL4337916 20080714 Gescan
DRR CLG1510680 20080714 Gescan
DRR DAR2639058 20080714 Gescan
DRR MTL4337917 20080714 Gescan
DRR CLG1510681 20080714 Gescan
DRR DAR2639059 20080714 Gescan
DRR MTL4337918 20080714 Gescan
DRR CLG1510682 20080714 Gescan
DRR DAR2639060 20080714 Gescan
DRR MTL4337919 20080714 Gescan
DRR CLG1510683 20080714 Gescan
DRR DAR2639061 20080714 Gescan
DRR MTL4337920 20080714 Gescan


Date2 is blank and this is where I want to show 2008/17/14.

Thanks,

"Gary''s Student" wrote:

> With 20080714 in cell C3, this macro will put the date in C4:
>
> Sub theresa()
> v = Range("C3").Value
> yr = Left(v, 4)
> mn = Mid(v, 5, 2)
> dy = Right(v, 2)
> Range("C4").Value = DateSerial(yr, mn, dy)
> End Sub
> --
> Gary''s Student - gsnu200797
>
>
> "Theresa" wrote:
>
> > Hi:
> >
> > I receive a file that contains a column of dates in a format that is not
> > recognized as a date: ie: 20080714. I am trying to create a macro to
> > insert the "/" at the required places.
> >
> > Here is the code I am using:
> >
> > Range("D3" & Range("E65536").End(xlUp).Row).FormulaR1C1 = Trim(Left(C3, 4)
> > & "/" & Mid(C3, 5, 2) & "/" & Right(C3, 2))
> >
> > I want to look at the data in Column E to see how far to go, then take the
> > date in Column C and put it in Column D in the correct format. When I run
> > the macro, all I get is // with nothing else.
> >
> > What am I doing wrong?
> >
> > Thanks,

 
Reply With Quote
 
Office_Novice
Guest
Posts: n/a
 
      5th Aug 2008
This Worked for me:

Option Explicit
Sub FixDates()
Dim YourRange As Range
Dim ws As Worksheet
Dim x As Integer
Dim i As Variant

Set ws = ActiveWorkbook.Worksheets(1)
Set YourRange = ws.Range("C:C")
x = 1

For Each i In YourRange
ws.Cells(x, 4).Value = Left(i, 4) & "/" & Mid(i, 5, 2) & "/" & Right(i, 2)
x = x + 1
Next
End Sub

Good luck.

"Theresa" wrote:

> Hi:
>
> I receive a file that contains a column of dates in a format that is not
> recognized as a date: ie: 20080714. I am trying to create a macro to
> insert the "/" at the required places.
>
> Here is the code I am using:
>
> Range("D3" & Range("E65536").End(xlUp).Row).FormulaR1C1 = Trim(Left(C3, 4)
> & "/" & Mid(C3, 5, 2) & "/" & Right(C3, 2))
>
> I want to look at the data in Column E to see how far to go, then take the
> date in Column C and put it in Column D in the correct format. When I run
> the macro, all I get is // with nothing else.
>
> What am I doing wrong?
>
> Thanks,

 
Reply With Quote
 
Office_Novice
Guest
Posts: n/a
 
      5th Aug 2008
After reading your response try this:

Option Explicit
Sub FixDates()
Dim YourRange As Range
Dim ws As Worksheet
Dim lastrow
Dim x As Integer
Dim i As Variant

lastrow = Cells(Cells.Rows.Count, "C").End(xlUp).Row
Set ws = ActiveWorkbook.Worksheets(1)
Set YourRange = ws.Range("C3:C" & lastrow)
x = 3

For Each i In YourRange
ws.Cells(x, 4).Value = Left(i, 4) & "/" & Mid(i, 5, 2) & "/" & Right(i, 2)
x = x + 1
Next
End Sub


"Theresa" wrote:

> Hi Gary:
>
> But I need it to evaluate how many rows to go down, and the dates will be
> different in each row. EG: I have dates in rows C3:C30 in the 20080714
> format. I need the dates to be in the 2008/07/14 format. The number of rows
> will change constantly so I need to evaluate how many rows to work with.
>
> Here is a small sample file:
>
> Carrier Pro/Inv Date Date2 Customer
> DRR CLG1510679 20080714 Gescan
> DRR DAR2639057 20080714 Gescan
> DRR MTL4337916 20080714 Gescan
> DRR CLG1510680 20080714 Gescan
> DRR DAR2639058 20080714 Gescan
> DRR MTL4337917 20080714 Gescan
> DRR CLG1510681 20080714 Gescan
> DRR DAR2639059 20080714 Gescan
> DRR MTL4337918 20080714 Gescan
> DRR CLG1510682 20080714 Gescan
> DRR DAR2639060 20080714 Gescan
> DRR MTL4337919 20080714 Gescan
> DRR CLG1510683 20080714 Gescan
> DRR DAR2639061 20080714 Gescan
> DRR MTL4337920 20080714 Gescan
>
>
> Date2 is blank and this is where I want to show 2008/17/14.
>
> Thanks,
>
> "Gary''s Student" wrote:
>
> > With 20080714 in cell C3, this macro will put the date in C4:
> >
> > Sub theresa()
> > v = Range("C3").Value
> > yr = Left(v, 4)
> > mn = Mid(v, 5, 2)
> > dy = Right(v, 2)
> > Range("C4").Value = DateSerial(yr, mn, dy)
> > End Sub
> > --
> > Gary''s Student - gsnu200797
> >
> >
> > "Theresa" wrote:
> >
> > > Hi:
> > >
> > > I receive a file that contains a column of dates in a format that is not
> > > recognized as a date: ie: 20080714. I am trying to create a macro to
> > > insert the "/" at the required places.
> > >
> > > Here is the code I am using:
> > >
> > > Range("D3" & Range("E65536").End(xlUp).Row).FormulaR1C1 = Trim(Left(C3, 4)
> > > & "/" & Mid(C3, 5, 2) & "/" & Right(C3, 2))
> > >
> > > I want to look at the data in Column E to see how far to go, then take the
> > > date in Column C and put it in Column D in the correct format. When I run
> > > the macro, all I get is // with nothing else.
> > >
> > > What am I doing wrong?
> > >
> > > Thanks,

 
Reply With Quote
 
Bernie Deitrick
Guest
Posts: n/a
 
      5th Aug 2008
Theresa,

Try this, which will create actual dates - this also assumes that your default date system is US...
It will take just a little rearrangement to do Euro style dates.

Sub TheresaTryNow()
With Range("D3" & Range("E65536").End(xlUp).Row)
.Formula = "=DATEVALUE(Mid(C3, 5, 2) & ""/"" & Right(C3, 2)& ""/"" & Trim(Left(C3, 4)))"
.NumberFormat = "mmmm dd, yyyy"
End With
End Sub


HTH,
Bernie
MS Excel MVP


"Theresa" <(E-Mail Removed)> wrote in message
news:49D9B2F8-FC50-458D-8E58-(E-Mail Removed)...
> Hi:
>
> I receive a file that contains a column of dates in a format that is not
> recognized as a date: ie: 20080714. I am trying to create a macro to
> insert the "/" at the required places.
>
> Here is the code I am using:
>
> Range("D3" & Range("E65536").End(xlUp).Row).FormulaR1C1 = Trim(Left(C3, 4)
> & "/" & Mid(C3, 5, 2) & "/" & Right(C3, 2))
>
> I want to look at the data in Column E to see how far to go, then take the
> date in Column C and put it in Column D in the correct format. When I run
> the macro, all I get is // with nothing else.
>
> What am I doing wrong?
>
> Thanks,



 
Reply With Quote
 
Theresa
Guest
Posts: n/a
 
      5th Aug 2008
Thanks, I just changed the date format and it works great!

"Bernie Deitrick" wrote:

> Theresa,
>
> Try this, which will create actual dates - this also assumes that your default date system is US...
> It will take just a little rearrangement to do Euro style dates.
>
> Sub TheresaTryNow()
> With Range("D3" & Range("E65536").End(xlUp).Row)
> .Formula = "=DATEVALUE(Mid(C3, 5, 2) & ""/"" & Right(C3, 2)& ""/"" & Trim(Left(C3, 4)))"
> .NumberFormat = "mmmm dd, yyyy"
> End With
> End Sub
>
>
> HTH,
> Bernie
> MS Excel MVP
>
>
> "Theresa" <(E-Mail Removed)> wrote in message
> news:49D9B2F8-FC50-458D-8E58-(E-Mail Removed)...
> > Hi:
> >
> > I receive a file that contains a column of dates in a format that is not
> > recognized as a date: ie: 20080714. I am trying to create a macro to
> > insert the "/" at the required places.
> >
> > Here is the code I am using:
> >
> > Range("D3" & Range("E65536").End(xlUp).Row).FormulaR1C1 = Trim(Left(C3, 4)
> > & "/" & Mid(C3, 5, 2) & "/" & Right(C3, 2))
> >
> > I want to look at the data in Column E to see how far to go, then take the
> > date in Column C and put it in Column D in the correct format. When I run
> > the macro, all I get is // with nothing else.
> >
> > What am I doing wrong?
> >
> > Thanks,

>
>
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      5th Aug 2008
Another way (manually) is to select the range and then use data|text to
columns. Fixed width, the field is a date in ymd order.

In code:

with activesheet
with .Range("C3:C" & .cells(.rows.count,"E").End(xlUp).Row)
.texttoColumns Destination:=.cells(1).offset(2,1), _
DataType:=xlFixedWidth, FieldInfo:=Array(0, 5)
end with
end with

But I would have thought that you would use column C to get the lastrow. And
that you'd start in D3, not D5.

You may not need this, but it uses column C and then plops the result right back
where it found the data.

with activesheet
with .Range("C3:C" & .cells(.rows.count,"C").End(xlUp).Row)
.texttoColumns Destination:=.cells(1), _
DataType:=xlFixedWidth, FieldInfo:=Array(0, 5)
end with
end with

Theresa wrote:
>
> Hi:
>
> I receive a file that contains a column of dates in a format that is not
> recognized as a date: ie: 20080714. I am trying to create a macro to
> insert the "/" at the required places.
>
> Here is the code I am using:
>
> Range("D3" & Range("E65536").End(xlUp).Row).FormulaR1C1 = Trim(Left(C3, 4)
> & "/" & Mid(C3, 5, 2) & "/" & Right(C3, 2))
>
> I want to look at the data in Column E to see how far to go, then take the
> date in Column C and put it in Column D in the correct format. When I run
> the macro, all I get is // with nothing else.
>
> What am I doing wrong?
>
> Thanks,


--

Dave Peterson
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting dates to current dates to find out the evaluation date Donica24 Microsoft Access Queries 1 26th Jan 2010 04:38 PM
Linking computer dates (time) to spreadsheet dates that have formu bigisle Microsoft Excel Worksheet Functions 2 3rd Jan 2010 08:05 PM
Copy/Paste 2009 dates into Tbale and they Show as 2008 Dates ryguy7272 Microsoft Access 1 13th Nov 2008 02:13 AM
Toggle a range of Julian dates to Gregorian Dates and Back =?Utf-8?B?UFNLZWxsaWdhbg==?= Microsoft Excel Programming 4 8th May 2007 05:51 AM
Showing data between two dates in multiple subreports by enter two dates Martijn Microsoft Access Reports 0 26th Sep 2003 10:37 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:52 AM.