https://ask.csdn.net/questions/7469816?expend=true
在我之前的提问中得到的代码,会出现在第二列执行后,其他列异常的情况,所以希望一个方法,使得excel让文字满一定字数就自动换到下个单元格,并且可以在不影响其他列的情况换单元格,还有如何可以让多个或者所有列都能换单元格?
请确保不会使其他单元格异常,或者其他多个单元格能正常操作,又或者所有单元格都能正常操作。请确认无误后再告诉我。
Sub aa()
m = 1 '从第几列
n = 4 '到第几列
For j = m To n
r = Range(Cells(65535, j), Cells(65535, j)).End(xlUp).Row
i = 1
Do While i <= r
l = Len(Cells(i, j).Value)
If l > 15 Then
Range(Cells(i, j), Cells(i, j)).Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Cells(i, j).Value = Left(Cells(i + 1, j).Value, 15)
Cells(i + 1, j).Value = Right(Cells(i + 1, j).Value, l - 15)
r = r + 1
End If
i = i + 1
Loop
Next
End Sub