我真的需要以下代码的帮助。我想在单元格的值之后添加分隔符。我对vba很新,所以如果您需要更详细的信息,请告诉我:
Sub NameSplit()
Dim var As Variant
Dim rw As Long
Dim i As Long
With Worksheets("Sheet1")
For rw = 2 To .Cells(.Rows.Count, "F").End(xlUp).Row
If CBool(Len(.Cells(rw, "F").Value2)) Then
var = Split(.Cells(rw, "F").Value2, Chr(32))
.Cells(rw, "A").Resize(1, UBound(var) + 1) = var
End If
Next rw
End With
End Sub
希望你能帮助我。非常感谢,并为我糟糕的编码感到抱歉:(
答案 0 :(得分:0)
尝试TextToColumns
:
Sub NameSplit()
Worksheets("Sheet1").Range("F:F").TextToColumns Destination:=Range("A1"), _
DataType:=xlDelimited, _
Semicolon:=True, _
FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1))
End Sub
修改强>
Sub NameSplit()
Dim var As Variant
Dim rw As Long, i As Long
With Worksheets("Sheet1")
For rw = 2 To .Cells(.Rows.Count, "F").End(xlUp).Row
var = Split(.Cells(rw, "F").Text, ";")
.Cells(rw, "A").Resize(1, UBound(var) + 1) = var
Next rw
End With
End Sub