功能: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
判断单元格内是否是有值的,可以排除有空格的影响