Remove Characters after certain # of characters reached

MatthewLane412

New Member
Joined
Aug 23, 2017
Messages
24
Hello,

I am trying to remove all character in column AK that exceed 14 character in length. I found some code online which works for column A only. I have been working on trying to get it to work with Column AK.

lastrow= Range ("A20000").End(xlUp)Row

For I = 1 To lastrow

If Len(Cells(I, 1)) >14 Then

Cells (I, 1) = Left (Cells (I, 1), 14)
End If

Next I



I was thinking code similar to this could work but I had no success.

Dim finRow As a String
finRow = Sheets("Data").Range("A20000").End(xlUp).Row

Set myRange = Sheets ("Data").Range (AK2:AK" & finRow)

Thank you for taking a look.
 

Some videos you may like

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.

leeavery3

New Member
Joined
Mar 6, 2014
Messages
16
Finding the last row you should you rows.count. this way you can insure you start from the very last row in your column.

AK is column 37

lastrow = Cells(Rows.Count, 37).End(xlUp).Row


For I = 1 To lastrow
If Len(Cells(I, 37)) > 14 Then
Cells(I, 37) = Left(Cells(I, 37), 14)
End If
Next I
 
Last edited:

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
52,898
Office Version
  1. 365
Platform
  1. Windows
Another option, without the loop
Code:
Sub MatthewLane412()
With Range("AK2", Range("AK" & Rows.Count).End(xlUp))
   .Value = Evaluate(Replace("if(@<>"""",left(@,14),"""")", "@", .Address))
End With
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,122,469
Messages
5,596,316
Members
414,053
Latest member
Dual Showman

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