我试图分裂单元格如果包含","到下一行我使用这个公式从sheet1(= Sheet1!B3)获取数据,依此类推,数据在B3:AF50。 我使用这个vba代码
Sub splitcells()
Dim InxSplit As Long
Dim SplitCell() As String
Dim RowCrnt As Long
With Worksheets("Sheet2")
RowCrnt = 3
Do While True
If .Cells(RowCrnt, "b").Value = "" Then
Exit Do
End If
SplitCell = Split(.Cells(RowCrnt, "b").Value, ",")
If UBound(SplitCell) > 0 Then
.Cells(RowCrnt, "b").Value = SplitCell(0)
For InxSplit = 1 To UBound(SplitCell)
RowCrnt = RowCrnt + 1
.Cells(RowCrnt, "b").Value = SplitCell(InxSplit)
.Cells(RowCrnt, "B").Value = .Cells(RowCrnt - 1, "B").Value
Next
End If
RowCrnt = RowCrnt + 1
Loop
End With
End Sub
问题是
我的单元格值就是那样
B3 ABC,XYZ,KKK,LLL 我希望它分裂为B3 = ABC和B4 = XYZ B5 = KKK b6 = LLL
如果B3中的值发生变化,它应该清除早期拆分的单元格(B4,B5,B6)并更新是否需要拆分标准","
有这样的表格
拆分后的应该看起来像公式完整