我十年來一直沒有在Excel中使用VBA,但希望找到一種編碼解決方案來更改20K單元格中的一堆文本。我的工作讓我手動做,但我知道必須有一個Comp Sci解決方案。試圖在Excel中更改單元格中的文本
我已經對我需要更改的列進行了排序。並且有成千上萬的重複項需要更改,如下面的示例所示
示例:1001.tif更改爲1001_1.tif,如果它是第一個副本,或者如果它是該值的第一個文本,則將其保留。
我下面的代碼根本不起作用,但應該是它的框架。
Sub Button1_Click()
Dim n As Integer
n = 1
Dim test As String
test = Cells(1, D).Text
Dim active As String
active = Cells(2, D).Text
For i = 2 To 12
active = Cells(i, D)
If active = test Then
Cells(i, D).Text = Microsoft.VisualBasic.Strings.Left(test, 4) + "_" + n + ".tif"
n = n + 1
Else
test = active
End If
Next i
Cells(1, a).Text = "Done"
End Sub
任何提示?
使用'.Value2'而不是'.Text' – Tom
謝謝,但是,我試過了,它仍然給我相同的運行時錯誤'1004'應用程序定義或對象定義的錯誤 –
看看下面的答案。你需要改變更多,然後只是 – Tom