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

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
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
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
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
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
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,214,376
Messages
6,119,172
Members
448,870
Latest member
max_pedreira

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