写一个A列以-为分列符号,分列出每行数字的VBA代码
时间: 2024-05-25 22:17:07 浏览: 77
Sub SplitColumn()
Dim cell As Range
Dim arr() As String
For Each cell In Selection
arr = Split(cell.Value, "-")
cell.Offset(0, 1).Resize(1, UBound(arr) + 1) = arr
Next cell
End Sub
注:此代码将选定区域中的每个单元格按照“-”分列符号分列,并将分列后的数字显示在相邻列中。
相关问题
写一个A列以-为分列符号,文字分列到B列,数字分列到C列的VBA代码
Sub SplitColumns()
Dim lastRow As Long
lastRow = Cells(Rows.Count, "A").End(xlUp).Row 'get last row of column A
Dim i As Long
For i = 1 To lastRow
Dim values() As String
values = Split(Cells(i, "A"), "-") 'split values by "-"
Cells(i, "B") = values(0) 'put first part in column B
Cells(i, "C") = values(1) 'put second part in column C
Next i
End Sub
写一个A列以()为分列符号,分列出每行数字的VBA代码
Sub SplitParentheses()
Dim cell As Range
Dim arr() As String
For Each cell In Selection
arr = Split(cell.Value, "()")
cell.Offset(0, 1).Resize(1, UBound(arr) + 1) = arr
Next cell
End Sub
说明:
1. 该代码适用于选定的单元格区域;
2. 将每个单元格中的内容按照()为分隔符进行拆分;
3. 将拆分后的结果放入单元格右侧的相邻单元格中。
阅读全文