Wrox Programmer Forums
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 22nd, 2006, 10:38 AM
Authorized User
 
Join Date: Jun 2004
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default Run time errors

What I am trying to do is search a currentregion for all dates stored as text and convert them to proper dates using the datevalue function. However when the code picks up a cell value that is anything other than a date stored as text then I get a run-time error 13 type mismatch and I am unable to get around it. Any ideas?

This was my attempt

Sub TextToDate()


Dim rngCurrentCell As Excel.Range
Dim dateTemp


Range("A10").Select
For Each rngCurrentCell In ActiveCell.CurrentRegion.Cells
    If IsError(DateValue(rngCurrentCell)) = False Then
    dateTemp = DateValue(rngCurrentCell)
    rngCurrentCell = dateTemp
    rngCurrentCell.NumberFormat = "dd/mm/yyyy;@"
    End If

Next rngCurrentCell


End Sub



 
Old August 22nd, 2006, 12:02 PM
Authorized User
 
Join Date: Jul 2006
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Mayby it is not the best solution, but it works:

Dim rngCurrentCell As Excel.Range
Dim dateTemp

Range("A10").Select
For Each rngCurrentCell In ActiveCell.CurrentRegion.Cells
On Error Resume Next'********************
    If IsError(DateValue(rngCurrentCell)) = True Then '************
Else'********************
    dateTemp = DateValue(rngCurrentCell)
    rngCurrentCell = dateTemp
    rngCurrentCell.NumberFormat = "dd/mm/yyyy;@"
    End If
Next rngCurrentCell

End Sub

 
Old August 23rd, 2006, 05:13 AM
Authorized User
 
Join Date: Jun 2004
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Many thanks, It works well.

I had tried using the 'on error resume next', and 'on error Goto', without any success. I was putting it after the IsError line so it wasn't working.






Similar Threads
Thread Thread Starter Forum Replies Last Post
errors during run-time Chacko C++ Programming 0 March 4th, 2007 02:33 PM
Design-Time or Run-Time now ? ALGNET .NET Framework 2.0 1 July 31st, 2006 04:43 AM
RUN-TIME ERRORS IN MY VB6 APPLICATION Nadalik VB How-To 1 June 15th, 2006 11:18 AM
Run time Help Dazzer96 Access VBA 2 May 3rd, 2006 07:03 AM
Run Time Customization B.V.Madhav Crystal Reports 1 May 10th, 2005 01:57 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.