[英]Remove or add text after a specific character in Excel
我的excel表中有很多數據,我想刪除Last( - )字符后的所有文本。 這是我的工作表中的示例數據
"This-is-car-44"
"This-is-my-school-ok"
我希望看起來像這樣
"This-is-car"
"This-is-my-school"
我想刪除所有文本后,所以他們的任何公式都是這樣做的。 還有一件事,如果可能的話,我可以在excel中做到這一點
"This-is-car-44"
"This-is-my-school-ok"
看起來像這樣
"This-is-car/"
"This-is-my-school/"
我的意思是在最后 - 刪除所有文本並添加此/最后。 謝謝。
你可以做這樣的事情。
Sub RemoveLastStingPart()
Dim rng As Range
Dim intLastRow As Long
Dim strTemp As String
Dim aryTemp() As String
With ActiveSheet
intLastRow = .UsedRange.Rows.Count
Set rng = .Range(Cells(1, 1), Cells(intLastRow, 1))
For Each cell In rng
strTemp = cell.Value
aryTemp = Split(strTemp, "-")
strTemp = ""
For i = 0 To UBound(aryTemp) - 1
strTemp = strTemp & aryTemp(i) & "-"
Next i
strTemp = Left(strTemp, Len(strTemp) - 1)
cell.Offset(0, 1).Value = strTemp
Next cell
End With
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.