Slow Macro

Philip1957

Board Regular
Joined
Sep 30, 2014
Messages
185
Office Version
  1. 365
Platform
  1. Windows
Greetings,
I have a macro that splits a date/timestamp in a single column into a column with the date and a column with the time. It runs clean but is very slow with large worksheets.
Any suggestions on how to speed it up?

VBA Code:
Option Explicit

Sub Split_Date_Time()

Application.ScreenUpdating = False

Application.DisplayAlerts = False

On Error Resume Next

Dim clmn As String

clmn = Application.InputBox("Enter the letter designating" & vbCrLf & _
    "the column where the date" & vbCrLf & "and time data is located.")

Columns(clmn).EntireColumn.Offset(0, 1).Select
    ActiveCell.EntireColumn.Insert Shift:=xlToRight

Columns(clmn).Select
    Selection.TextToColumns Destination:=Columns(clmn), DataType:=xlFixedWidth, _
        FieldInfo:=Array(Array(0, 3), Array(10, 1)), TrailingMinusNumbers:=True
    Columns(clmn).Select
    Selection.NumberFormat = "m/d/yy;@"
    ActiveCell.EntireColumn.Offset(0, 1).Select
    Selection.NumberFormat = "h:mm;@"

Selection(1).Activate
    ActiveCell.Value = "Add Time"
    ActiveCell.Font.Bold = True
    ActiveCell.HorizontalAlignment = xlCenter
    ActiveCell.Borders.ColorIndex = 1
    
Range(clmn & Rows.Count).End(xlUp).Select
ActiveCell.Offset(0, 1).Select
Do Until ActiveCell.Row = "1"
    ActiveCell.Borders.ColorIndex = 1

ActiveCell.Offset(-1, 0).Select

Loop

Application.ScreenUpdating = True

End Sub  'Split_Date_Time()

Any assistance is greatly appreciated.

~ Phil
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
try changing this part of your code:

VBA Code:
Range(clmn & Rows.Count).End(xlUp).Select
ActiveCell.Offset(0, 1).Select
Do Until ActiveCell.Row = "1"
    ActiveCell.Borders.ColorIndex = 1

ActiveCell.Offset(-1, 0).Select

Loop

to this:

Power Query:
    Dim lastrow As Long
    lastrow = Range(clmn & Rows.Count).End(xlUp).Row
    Range(clmn & "1", clmn & lastrow).Borders.ColorIndex = 1
 
Upvote 0
Solution
Sorry it took so long for me to get back to you. Yes that runs much faster. Thanks!
 
Upvote 0

Forum statistics

Threads
1,224,816
Messages
6,181,141
Members
453,021
Latest member
Justyna P

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