Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9120177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:34:11+00:00 2026-06-17T05:34:11+00:00

I am using the following vba code to change a text string date into

  • 0

I am using the following vba code to change a text string date into an actual date in excel so I can use it for logical comparisons and the like.

The problem is I need this to work for around 4000 rows and update it weekly, and this code is very slow.

Sub Datechange()

Dim c As Range
    For Each c In Range("D2:D" & Range("D" & Rows.Count).End(xlUp).Row)
        c.Value = CDate(c.Value)
    Next c

End Sub

Are there any alternative ways I could do the same thing quicker? I am assuming part of the reason it is so slow is because there are overheads involved with selecting single cells and processing the code over and over but I am not sure how to do it any other way?

Also some of the rows at the bottom contain the words “None Specified” and when the code reaches these cells it breaks with

Run-time error ’13’: Type mismatch

Is there a way to stop this happening so the following code can complete?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T05:34:11+00:00Added an answer on June 17, 2026 at 5:34 am

    First steps would be:

    • Turn screen updating off
    • Turn calculation off
    • Read and write the range at once

    It could look like the code below – it is a good idea to include an error handler to avoid leaving your spreadsheet with screen updates off or with the calculation mode changed:

    Sub Datechange()
    
        On Error GoTo error_handler
    
        Dim initialMode As Long
    
        initialMode = Application.Calculation 'save calculation mode
        Application.Calculation = xlCalculationManual 'turn calculation to manual
        Application.ScreenUpdating = False 'turn off screen updating
    
        Dim data As Variant
        Dim i As Long
    
        'copy range to an array
        data = Range("D2:D" & Range("D" & Rows.Count).End(xlUp).Row)
    
        For i = LBound(data, 1) To UBound(data, 1)
            'modify the array if the value looks like a date, else skip it
            If IsDate(data(i, 1)) Then data(i, 1) = CDate(data(i, 1))
        Next i
    
        'copy array back to range
        Range("D2:D" & Range("D" & Rows.Count).End(xlUp).Row) = data
    
    exit_door:
        Application.ScreenUpdating = True 'turn screen updating on
        Application.Calculation = initialMode 'restore original calculation mode
    
        Exit Sub
    
    error_handler:
        'if there is an error, let the user know
        MsgBox "Error encountered on line " & i + 1 & ": " & Err.Description
        Resume exit_door 'don't forget the exit door to restore the calculation mode
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the following VBA code to change the color of the rows
In Excel-VBA, I am saving a file using the following code: fullFileName = Application.GetSaveAsFilename(...)
Using following code I try to get updated list of checkbuttons' corresponding text values,
I am creating date using following code try { newdatetime = new DateTime(2012, 2,
I am using VBA for Excel 2010 and randomly receiving the following error: Run-time
The following Visio macro (using VBA) rotates the currently selected shape: ActiveWindow.Selection.Rotate90 How can
I am using the following VBA code to export PPT slides to images. The
I'm using the following VBA code to automate moving a row on one sheet
I have the following VBA code inside an Excel macro: With ActiveSheet.QueryTables.Add( _ Connection:=ConnStr,
the following VBA code should be correct: Function BlackScholes(CallPutFlag As String, S As Double,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.