字符串分割,文末示例(文末代码3附有源码)
代码1 - 基础字符串
代码2 - 字符串拆分
代码3 - 字符串分割
Option Explicit
Sub WorkbooksClear()
Dim DataRange As Range
Set DataRange = Range("C2:E12")
DataRange.Clear
End Sub
Sub WorkbooksTest()
Dim DataRange As Range
Set DataRange = Range("A2:A12")
Dim DataRowCount As Long
DataRowCount = DataRange.Rows.Count
Dim Index As Integer
For Index = 1 To DataRowCount
Dim Item As Range
Set Item = DataRange.Cells(Index, 1)
Dim Items() As String
Items = VBA.Split(Item, "-")
Dim StringIndex As Integer
For StringIndex = LBound(Items) To UBound(Items)
Item.Offset(0, StringIndex + 2).Value = Items(StringIndex)
Next StringIndex
Next Index
End Sub
关注
笔者 - jxd