ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excel macro - truncate cell at X characters (left to right) (https://www.excelbanter.com/excel-programming/394964-excel-macro-truncate-cell-x-characters-left-right.html)

E2goJJM

Excel macro - truncate cell at X characters (left to right)
 
Need to create a macro to be able to truncate the contents of cells at X
characters. X will always be the same value. X will be counted left to
right

Ex. If X = 5
ABC1234 would be truncated to ABC12

Tom Ogilvy

Excel macro - truncate cell at X characters (left to right)
 

sub ABC()
Dim x as Long, cell as Range
x = 5
for each cell in selection
cell.Value = left(cell.Value,x)
Next
end sub

--
Regards,
Tom Ogilvy


"E2goJJM" wrote:

Need to create a macro to be able to truncate the contents of cells at X
characters. X will always be the same value. X will be counted left to
right

Ex. If X = 5
ABC1234 would be truncated to ABC12



All times are GMT +1. The time now is 10:04 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com