The offset satement was wrong. the code below should work. I create a set
statement so you can see how the code should work.
Set SerialRange = Range("A1:A10")
For Each SerialRng In SerialRange
myserial = Left(SerialRng.Offset(0, 3), 6)
record_serial = DateSerial(Mid(myserial, 5, 2), _
Left(myserial, 2), Mid(myserial, 3, 2))
Next SerialRng
"tracktraining" wrote:
> the code is erroring out at this location:
> record_serial = DateSerial(mid(myserial,5,2),
> Left(Myserial,2),mid(myserial,3,2) )
>
> During these two lines (see below), i am trying to 1.) read the first 6
> digits then 2.) convert to format mm/dd/yy. Maybe it would help if i told you
> that the serial number is in column is D.
>
> myserial = Left(SerialRng.cells(SerialRng.row, 4), 6)
> record_serial = Format(myserial, "mm/dd/yy")
>
> thanks!
> --
> Learning
>
>
> "Joel" wrote:
>
> > For Each SerialRng In SerialRng.cells
> > myserial = Left(SerialRng.cells.offset, 6)
> > record_serial = DateSerial(mid(myserial,5,2),
> > Left(Myserial,2),mid(myserial,3,2) )
> > On Error Goto Next SerialRng ***(see note below)
> > If record_serial >= startserial And record_serial <= endserial Then
> > SerialRng.EntireRow.Copy
> > Sheets("Data").Select
> > cells(Rows.count, 1).End(xlUp)(2).Select
> > Selection.PasteSpecial Paste:=xlAll
> > End If
> > Next SerialRng
> >
> >
> > "tracktraining" wrote:
> >
> > > Hi Everyone,
> > >
> > > I have a column that contains serial numbers in this format - mmddyy - ###
> > > (i.e. 060308-001).
> > > I would like to split out the first 6 digits and convert it into a date
> > > (mm/dd/yy).
> > > I tried to do this with the following code and it doesn't work:
> > >
> > > '------start code
> > >
> > > startserial = Format(Me.Start_Serial, "mm/dd/yy")
> > > endserial = Format(Me.End_Serial, "mm/dd/yy")
> > >
> > > For Each SerialRng In SerialRng.cells
> > > myserial = Left(SerialRng.cells(SerialRng.row, 4), 6)
> > > record_serial = Format(myserial, "mm/dd/yy")
> > > On Error Goto Next SerialRng ***(see note below)
> > > If record_serial >= startserial And record_serial <= endserial Then
> > > SerialRng.EntireRow.Copy
> > > Sheets("Data").Select
> > > cells(Rows.count, 1).End(xlUp)(2).Select
> > > Selection.PasteSpecial Paste:=xlAll
> > > End If
> > > Next SerialRng
> > >
> > > '---- end code
> > >
> > > ***here I would like for it to skip to the next SerialRng if cannot get the
> > > first 6 digit to convert into a date - sometimes the field may not be a
> > > serial number and just some other ID number so it can't be converted into a
> > > date.
> > >
> > > Please help if possible.
> > >
> > >
> > > Thank you!
> > > tracktraining
> > >
> > >
> > > --
> > > Learning
|