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.
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
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:
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
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