作者windknife18 (windknife18)
标题Re: [问题] VBA应用,字串补上前面的数字
时间Sun Jan 21 14:40:17 2024
好久没有写VBA了,练习一下,假如你的资料是在A栏(A2开始)
Sub Test()
Dim lRow As Long
Dim arrStr() As String
Dim preStr As String
Dim str As String
Dim l As Integer
lRow = ActiveSheet.UsedRange.Rows.Count
Application.ScreenUpdating = False
For i = 2 To lRow
str = ""
arrStr = Split(Cells(i, 1), "/")
For j = LBound(arrStr) To UBound(arrStr)
If Len(arrStr(j)) > 3 Then
preStr = arrStr(j)
str = str + arrStr(j) + "/"
Else
l = Len(arrStr(j))
str = str + Left(preStr, Len(preStr) - l) + arrStr(j) + "/"
End If
Next j
Cells(i, 2) = Left(str, Len(str) - 1)
Next i
Application.ScreenUpdating = True
MsgBox "Finish!!!"
End Sub
※ 引述《Tutelary83 ()》之铭言:
: Office 2016
: 请问各位板上大大,如果是像这样的资料有机会使用VBa自动将字串全数列出来吗?
: https://i.imgur.com/4rsTpie.jpg
: 因为系统的关系,所以在Key in资料时会用/分隔不同号码,但整理资料时就有点棘手,因为有些资料可能有2~10几个/,因此想请问看看VBA是否有机会用回圈完成,谢谢
: 例如:
: 23136225/27想整理成23136225/23136227!
: 22222222/23/33333331/2整理成22222222/22222223/33333331/33333332!
: -----
: Sent from JPTT on my iPhone
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 1.34.58.193 (台湾)
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Office/M.1705819219.A.1FD.html