我有一個名單,我想刪除某些文字如何刪除符號「_」和「 - 」前後的文本?
- HY_5AP001KL10輸出5AP001KL10
- 5AP0015K20_HY輸出5AP0015K20
- HW-5AP002H20輸出5AP002H20
- 5AP002lE_LEE SPRING輸出5AP002lE
- NAS4021-2E- 12輸出NAS4021-2E-12
在上面提到的列表中我想刪除HY前後的符號_
和HW前後-
以及後面的所有符號_
作爲第4條中提到的LEE SPRING,並且不得刪除最後一項的-2E或-12。有人可以幫助這個。上面提到的列表將是每個單元格的單個項目。
這裏是我的代碼......但問題是我不能夠「後需要刪除文本」,如圖列表項4
Sub Replace_Characters()
row_number = 1
Do
DoEvents
row_number = row_number + 1
the_description = Sheet2.Range("A" & row_number)
the_description = Replace(the_description, "HY", "")
the_description = Replace(the_description, "HY-", "")
the_description = Replace(the_description, "_HY", "")
the_description = Replace(the_description, "-HY", "")
the_description = Replace(the_description, "HY", "")
Sheet2.Range("A" & row_number) = the_description
Loop Until row_number = 20
End Sub
到目前爲止,你的代碼是什麼?你在掙扎什麼?很高興看到你的代碼,但沒有人會從頭開始爲你寫代碼。 – teylyn
如果您發佈了一個或兩個項目的預期輸出,您還將獲得更多信息。這種文字描述可能難以理解。產量是王道。 –
這裏是我的代碼......但問題是我不能夠經過「_」,如下列表項4個 子Replace_Characters() ROW_NUMBER = 1 做 的DoEvents ROW_NUMBER = ROW_NUMBER +刪除文本1 the_description = Sheet2.Range(「A」&row_number) the_description =替換(the_description,「HY_」,「」) the_description =替換(the_description,「HY-」,「」) the_description =替換(the_description, 「_HY」,「」) the_description =替換(the_description,「-HY」,「」) the_description =替換(the_description,「HY」,「」) Sheet2.Range(「A」&row_number)= the_description Loop Until row_number = 20 End Sub –