写一段vba代码,对Excel单列进行分列,以表格中文字“籍”为界,将一列分成两列
时间: 2023-02-18 22:21:51 浏览: 71
Sub SplitCol()
Dim rng As Range
Dim i As Long
Dim j As Long
Dim str As String
Set rng = Range("A1:A" & Range("A65536").End(xlUp).Row)
For i = 1 To rng.Rows.Count
str = rng.Cells(i, 1).Value
For j = 1 To Len(str)
If Mid(str, j, 1) = "籍" Then
rng.Cells(i, 2).Value = Right(str, Len(str) - j)
rng.Cells(i, 1).Value = Left(str, j - 1)
Exit For
End If
Next j
Next i
End Sub
相关问题
写一段vba代码,在Excel表格中B列中的每一个表格内加中文字“籍”
Sub AddWord()
Dim xCell As Range
For Each xCell In Range("B1:B" & Cells(Rows.Count, "B").End(xlUp).Row)
xCell.Value = xCell.Value & "籍"
Next
End Sub
帮我写一段vba代码:以I列数据,从小到大对整个表进行排序
下面是一段 VBA 代码,可以按照 I 列中的数据,从小到大对整个表进行排序:
```
Sub sortData()
Dim lastRow As Long
lastRow = Cells(Rows.Count, "I").End(xlUp).Row ' 获取 I 列最后一行的行数
Range("A1").CurrentRegion.Sort Key1:=Range("I1"), Order1:=xlAscending, Header:=xlYes ' 对整个表进行排序
End Sub
```
请将此代码复制到你的 VBA 编辑器中,并在需要时运行此代码即可。