Private Sub Command1_Click()
Dim j As String
j = "lk:x:df,sd:a:sdfg:sdfg:asdg:f:b,sd:f:g,sd:fh,sdfb,sadfg,truy,scvbn,asdf,g324rt,346,dfb,fh,esdg,s:dfh,gj,sdfh"
Dim k As Long
Dim row As Long
Dim col As Long
Dim z2() As String
Dim z1() As String
'以上是变量定义及测试数据定义
z1() = Split(j, ",")
MSFlexGrid2.Rows = UBound(z1()) + 2
'生成行数
For row = 0 To UBound(z1())
z2 = Split(z1(row), ":")
If UBound(z2()) + 2 > MSFlexGrid2.Cols Then
'如果当前列数不足,则修改总列数
MSFlexGrid2.Cols = UBound(z2()) + 2
End If
MSFlexGrid2.TextMatrix(row + 1, 0) = row + 1
'显示行号
For col = 0 To UBound(z2())
MSFlexGrid2.TextMatrix(row + 1, col + 1) = z2(col)
'空行号及标题栏,显示内容
Next
Next
For col = 0 To MSFlexGrid2.Cols - 2
MSFlexGrid2.TextMatrix(0, col + 1) = col + 1
Next
End Sub