|
本帖最后由 weiyingde 于 2016-9-11 10:36 编辑
把它改成3列,变成:
Private Sub CommandButton1_Click()
Dim Xm() As String, Arr() As String '声明两个动态数组,定义为字符型
Dim s As Integer, n As Integer
Xm = Split(Range("a1"), ",") '把文本转换为数组
s = UBound(Xm)
n = 0
For i = 0 To s
n = n + 1
ReDim Preserve Arr(1 To 3, 1 To n) '改变动态数组的大小,共2行,n列
Arr(1, n) = n
If Right(Xm(i), 3) = "(女)" Then '如果后面三个字符是“(女)”
Arr(2, n) = Left(Xm(i), Len(Xm(i)) - 3) '取前面的字符
Arr(3, n) = "女"
Else
Arr(2, n) = Xm(i)
Arr(3, n) = "男"
End If
Next
Range("b6").Resize(n, 3) = WorksheetFunction.Transpose(Arr) '把结果保存到工作表指定的单元格中
End Sub
|
|