Excel VBA 單元格內字符串截取


功能:v列有值的單元格內字符串截取

 1 Sub Demo3()
 2 Dim str
 3     With ActiveSheet
 4          For i = 2 To .Range("v65535").End(xlUp).Row
 5              If Not Len(Trim(ActiveSheet.Cells(i, 22))) = 0 Then
 6                  str = ActiveSheet.Cells(i, 22)
 7                  ActiveSheet.Cells(i, 22 - 6) = Left(str, InStr(str, "///") - 1)
 8                  ActiveSheet.Cells(i, 22 - 4) = Right(str, Len(str) - InStrRev(str, "/"))
 9                  ActiveSheet.Cells(i, 22 - 5) = Mid(str, InStr(str, "///") + 3, InStrRev(str, "///") - (InStr(str, "///") + 3))
10              End If
11          Next
12     End With
13     MsgBox ("恭喜你完成任務!")
14 End Sub

講一下:

Range("v65535").End(xlUp).Row

  獲得Excel最下面一個有內容的單元格的行

Len(Trim(ActiveSheet.Cells(i, 22))) = 0

  判斷單元格內是否是有值的,可以排除有空格的影響


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM