作者fumizuki (蒙面加菲狮)
看板Visual_Basic
标题Re: [VBA ] 关於Cells.Replace
时间Mon Dec 18 20:21:47 2006
※ 引述《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
1F:推 nightspirit:十分感谢>"< 12/18 23:06
※ 编辑: fumizuki 来自: 60.248.175.60 (12/19 12:29)
2F:推 fumizuki:抱歉,打错字也用错字...Cells 是用数字索引 12/19 12:29
3F:推 fumizuki:Range 是用名称索引 12/19 12:29
4F:推 Marty:倒数第三行跟第二行矛盾....^^ 12/19 14:37