如果字符串在第 9 个字符中有 - 符号,我需要一个宏来将字符串的一部分从 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
任何帮助深表感谢。
谢谢你。