A
A
Anton2014-06-06 17:49:19
excel
Anton, 2014-06-06 17:49:19

Macro to shorten cell text

It is required to create a macro that looks through all the cells of the specified column, and those in which the text length is more than N characters are reduced to N.
Please post the finished code :)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yuri Lobanov, 2014-06-06
@jezzit

Sub text_cut()
Dim i As Long, col As Long, text As String, q, lr
q = 4 ' количество символов
col = 1 ' номер столбца
lr = Cells(Rows.Count, col).End(xlUp).Row
    For i = 1 To lr
        text = Cells(i, col).Value
        Cells(i, col).Value = Left(text, q)
        Next i
    End
End Sub

G
GavriKos, 2014-06-06
@GavriKos

You need a freelance exchange.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question