如果字符串在第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
任何帮助深表感谢。
谢谢。
如果您的数据如上面示例中所示,那么您不需要VBA。您也可以使用Text To Columns :) – 2013-02-17 06:34:48