[英]Split cells with formula in next row Excel vba
I am trying to split cells if contain "," to next row i am using this formula to get data from sheet1 (=Sheet1!B3) and so on and data is in B3:AF50. 我试图拆分单元格如果包含“,”到下一行我使用这个公式从sheet1(= Sheet1!B3)获取数据,依此类推,数据在B3:AF50。 i use this vba code
我用这个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
Problem is 问题是
my cell values are like that 我的细胞价值就是这样
B3 ABC,XYZ,KKK,LLL i want it to split as B3 = ABC and B4 = XYZ B5 = KKK b6 = LLL B3 ABC,XYZ,KKK,LLL我希望它分为B3 = ABC和B4 = XYZ B5 = KKK b6 = LLL
and if value in B3 is changed it should clear the cells (B4,B5,B6)splitted early and update if split required criteria "," 如果B3中的值发生变化,它应该清除早期拆分的单元格(B4,B5,B6),如果拆分需要标准则更新“,”
Have sheet like that 有这样的表
after split should look like that with formula intact 拆分后应该看起来像配方完好无损
No VBA is needed. 不需要VBA。
With data in Sheet1 cell B3 , put this in any cell of any sheet: 使用Sheet1单元格B3中的数据,将其放在任何工作表的任何单元格中:
=TRIM(MID(SUBSTITUTE(Sheet1!$B3,",",REPT(" ",999)),COLUMNS($A:A)*999-998,999))
and copy across. 并复制。
EDIT#1: 编辑#1:
To copy downwards , use this formula instead: 要向下复制,请使用此公式:
=TRIM(MID(SUBSTITUTE(Sheet1!B$3,",",REPT(" ",999)),ROWS($1:1)*999-998,999))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.