[英]How do I replace part of a string from one cell from a string in another cell?
[英]VBA: How to copy part of the string from one cell and replace part of another cell with it?
我在excel中的文本如下所示:
[tab]第01節。
*第1節的名稱
文本
文本
文本
[tab]第2節。
*第2節的名稱
文本
...
我想在列(1、2、3 ...)中找到下一個SECTION,僅復制字符串SECTION 01.(02.,03。,...,52。,...)並將其粘貼到下面的單元格中僅替換*。
excel中的最終結果應如下所示:
第01節。第1節的名稱
文本
文本
文本
第02節。第2節的名稱
文本
...
我試圖記錄宏,但是它只將相同的文本復制到指定的一個單元格中,因此我將不得不重新排列VB代碼。 有人可以幫忙嗎?
謝謝,
此代碼迭代a
( col
= 1) col
並在找到“ [tab]”時將sctn
變量設置為單元格的值(忽略“ [tab]”)
找到“ *”時,將其替換為sctn
變量的內容
Dim row as Integer,col as Integer,sctn as String
col=1
row=1
While Cells(row,col)<>""
If Instr(Cells(row,col),"[tab]")>0 Then
sctn=Replace(Cells(row,col),"[tab]","")
Cells(row,col)=sctn
Else
Cells(row,col)=Replace(Cells(row,col),"*",sctn)
End If
row=row+1
Wend
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.