本文介绍了Excel宏:如果单元格的最终字符是“某事物”,那么然后,切割它们并将它们粘贴到别处的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是前面提到的问题的扩展,这个问题得到了惊人的回答,让我想到了如何简化我的草率代码。

This is an extension of a previously asked question that was amazingly answered and made me think of how else I can simplify my sloppy code.

Dim i As Long, l As Long
l = Cells(Rows.Count, 4).End(xlUp).Row
For i = l To 1 Step -1
  If Right(Cells(i, 4).Value, 4) = " XX " Then 

   'do some stuff to cut and paste that ending to ColumnE'
    Cells(i, 5) = " XX "

   'i'm trying to do something like this to clear the final 4 characters.
    Right(Cells(i, 4).Value, 4).ClearContents

  End If
Next i


推荐答案

取字符串的左边,字符数等于总长度减去4

Take the left of the string, the number of chars is equal to the total length minus 4

Cells(i,4).Formula = Left(Cells(i, 4).Value, len(Cells(i, 4).Value)-4)

这篇关于Excel宏:如果单元格的最终字符是“某事物”,那么然后,切割它们并将它们粘贴到别处的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 15:19