Trunicate columns... Too slow! Faster way?

Technowolf

Board Regular
Joined
Aug 28, 2014
Messages
181
I'm using:
Code:
    Columns("AG:AG").Select    
Dim rCell As Range
    For Each rCell In ActiveSheet.UsedRange.Columns("AG").Cells
        rCell = Left(rCell, 9)
    Next rCell

To truncate my characters down. Problem is I've got like 11k rows and it takes forever. Is there a faster way to do the entire column?
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,358
Office Version
  1. 365
Platform
  1. Windows
Why not insert a blank column to the right of column AG, put this formula in the first row of the new column, copy down, then copy and paste special values from the new column to column AG and finally delete the column you inserted?

All of which could be done with code, if that's what you need.
 
Upvote 0

Technowolf

Board Regular
Joined
Aug 28, 2014
Messages
181
It needs to be VBA, but that's not a terrible idea. Pretty much I need to shorten it to 9 characters, then format it to m/d/yyyy, all via macro, and without it taking forever to run.
 
Upvote 0

Technowolf

Board Regular
Joined
Aug 28, 2014
Messages
181
Date and time, but just needs to be date. The obvious solution would be to just format for date right? Well that makes it display properly, except I've got another complex formula elsewhere that if I just change the formatting to date it won't work, have to actually cut off the time.
 
Upvote 0

shg

MrExcel MVP
Joined
May 7, 2008
Messages
21,836
Office Version
  1. 2010
Platform
  1. Windows
Code:
Sub x()
    Columns("AH").Insert
    With Intersect(Columns("AG"), ActiveSheet.UsedRange)
        .Offset(, 1).FormulaR1C1 = "=int(rc[-1])"
        .Value = .Offset(, 1).Value
        .NumberFormat = "m/d/yyyy"
        .Offset(, 1).EntireColumn.Delete
    End With
End Sub
 
Upvote 0

Technowolf

Board Regular
Joined
Aug 28, 2014
Messages
181
Ah! Very clever shg! That worked absolutely perfectly. You're my hero!
 
Upvote 0

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
38,150
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
Here is another macro that you can consider which does not involve inserting/deleting a helper column...
Code:
Sub TruncateToNineCharacters()
  Dim Addr As String
  Addr = "AG1:AG" & Cells(Rows.Count, "AG").End(xlUp).Row
  Range(Addr) = Evaluate("IF(ROW(),INT(" & Addr & "))")
  Range(Addr).NumberFormat = "m/d/yyyy"
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,191,687
Messages
5,988,077
Members
440,125
Latest member
vincentchu2369

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
Top