Re: [問題] VBA應用,字串補上前面的數字

看板Office作者 (windknife18)時間3月前 (2024/01/21 14:40), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
好久沒有寫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://www.ptt.cc/bbs/Office/M.1705819219.A.1FD.html
文章代碼(AID): #1bhBnJ7z (Office)
文章代碼(AID): #1bhBnJ7z (Office)