使用macros剪切并粘贴一个string的一部分

如果string在第9个字符中有一个 – 符号,我需要一个macros将string的一部分从A列剪切并粘贴到B列。 我发现一些代码在stackoverflow将复制/粘贴文本部分,但不剪切/粘贴。 我的数据看起来像这样

SUBIAIUP-456253 SUBIAIUP-254 

这是我迄今为止的代码:

 Public Sub LeftSub() Dim cell As Range Dim sourceRange As Range Set sourceRange = Sheet1.Range("A1:A180") For Each cell In sourceRange If Mid(cell.Value, 9, 1) = "-" Then 'this code should cut/paste the value from col A to col B, not copy/paste Sheets("Sheet1").Range("B" & cell.Row).Value = Mid(cell.Value, 9, 20) End If Next End Sub 

任何帮助深表感谢。
谢谢。

如果你想把你粘贴到列B的值从列A中删除,使用这个:

 If Mid(cell.Value, 9, 1) = "-" Then cell.Offset(, 1).Value = Mid(cell.Value, 9) cell.Value = Left(cell, 8) End If 

正如Sid和Brett指出的那样,如果我们从中点获取其余的值,则不需要Mid函数的字符数量。 如果您想在列B值开始处显示短划线,请将中点设置为9.如果您想忽略它,请将其设置为10。

如果你想从列A到B剪切/粘贴整个值,使用这个:

 If Mid(cell.Value, 9, 1) = "-" Then 'this code WILL cut/paste the value from col A to col B, not copy/paste cell.Cut cell.Offset(, 1) End If