Re: [VBA ] 關於Cells.Replace

看板Visual_Basic作者 (矇面加菲獅)時間19年前 (2006/12/18 20:13), 編輯推噓4(400)
留言4則, 3人參與, 最新討論串2/2 (看更多)
※ 引述《nightspirit (鞭策自己社清流夜靈)》之銘言: : 目前我需要將時間表裡的時間格式大量置換 : 原本格式 5'20" <- excel視為字串 : 要置換為 00:05:20 <- excel視為時間 : 初步的想法是用loop來跑 : loop m=0 to 60 : loop s=0 to 60 : Replace m's" to 0:m:s : end loop : end loop : 但因為對VBA語法不熟(之前都只寫C >"<) : 想請各位高手賜教一下 >"< : 到底正確的寫法是如何??? '儲存格範圍:A1 ~ A999 Dim oldstr As String, newstr As String, m As String, s As String Dim i1 As Integer, i2 As Integer For i = 1 To 999 oldstr = Range("A" & i).Value i1 = Instr(oldstr, "'") If i1 > 0 Then i2 = InStr(i1 + 1, oldstr, Chr(34)) If i1 > 0 And i2 > 0 Then m = Left(oldstr, i1 - 1) s = Mid(oldstr, i1 + 1, i2 - i1 - 1) newstr = "00:" If Val(m) < 10 Then newstr = newstr & "0" newstr = newstr & Val(m) & ":" If Val(s) < 10 Then newstr = newstr & "0" newstr = newstr & Val(s) Range("A1").Value = newstr End If Next -- ▃▅▇▆▄ ▆▂▃ ` 逝去感如何能留住,半點遺留殊不易,██▅▇▄▃ ▇▃▂" . █████████▃i ▁▄▇ 更多悽悽慘慘的遭遇………██▆▃ █▅▆▃ˍ▄* ▂█▄▇▅▂. 我不知道,王~八~蛋~~! ▂▆███ █▄▃ 。fumizuki。Check。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.184.116.55

12/18 23:06, , 1F
十分感謝>"<
12/18 23:06, 1F
※ 編輯: fumizuki 來自: 60.248.175.60 (12/19 12:29)

12/19 12:29, , 2F
抱歉,打錯字也用錯字...Cells 是用數字索引
12/19 12:29, 2F

12/19 12:29, , 3F
Range 是用名稱索引
12/19 12:29, 3F

12/19 14:37, , 4F
倒數第三行跟第二行矛盾....^^
12/19 14:37, 4F
文章代碼(AID): #15XeNFFt (Visual_Basic)
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
文章代碼(AID): #15XeNFFt (Visual_Basic)