好,我有很多的字符串操作一樣哪個更快,可變或直接訪問單元值?
1st one
ActiveSheet.Cells(i, "B").Value = Replace(ActiveSheet.Cells(i, "B").Value, ",", " ")
ActiveSheet.Cells(i, "B").Value = Replace(ActiveSheet.Cells(i, "B").Value, "/", " ")
ActiveSheet.Cells(i, "B").Value = Replace(ActiveSheet.Cells(i, "B").Value, "&", " ")
ActiveSheet.Cells(i, "B").Value = Replace(ActiveSheet.Cells(i, "B").Value, "(", " ")
2nd one
store=ActiveSheet.Cells(i, "B").Value
store= Replace(store, "/", " ")
store = Replace(store, "&", " ")
store = Replace(store, "(", " ")
和一些修剪操作,有時找到字符串的長度,有時比較。
我必須爲單元格1到4000循環。問題是將單元格值存儲在字符串中,並且訪問更好更快?或者寫入宏中的activesheet單元格值本身更快?
store = activesheet.cells(i,"B").value and use store everywhere
or write activesheet.cells(i,"B").value everywhere?
哪個更好哪個更優化,我有點想,如果我們提到它去片和拿回來的單元格的值,但如果我們把它存儲在變量,那麼它可能會更快。我只需要知道哪個更好?
如果你是不知道,如果句子包括3項,雖然它是更多的代碼行,使用instr在替換之前查看字符是否存在會更快。即使沒有替換,替換也是一項成本很高的操作。 – aevanko
如果您正在進行大量的字符串操作,那麼值得查看正則表達式。 – Reafidy