我在excel中有这组数据,
2006-12-29
2007-01-01
2007-01-02
2007-01-03
2007-01-04
2007-01-05
2007-01-08
2007-01-09
2007-01-10
2007-01-11
2007-01-12
等..(2612行数据)
我想保留日期格式CCYY / MM / DD并添加括号和单词" Money"达到这个结果:
[CCYY/MM/DD] [Money],
[CCYY/MM/DD] [Money],
[CCYY/MM/DD] [Money],
我正在使用此代码:
Sub addbrackets()
Dim Rng As Range
Dim WorkRng As Range
On Error Resume Next
xTitleId = "DDL.PTBV"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
For Each Rng In WorkRng
Rng.Value = "[" & Rng.Value & "]" & "[Money],"
Next
End Sub
但它让我发送[2006年12月29日] [钱],错误的日期格式..
有人可以帮助我吗?
ps:我试图更改" 2"中的格式类型(文字)但它仍然不起作用
答案 0 :(得分:1)
Rng.Value = "[" & Format(Rng.Value, "YYYY/MM/DD") & "]" & "[Money],"
答案 1 :(得分:0)
首先获取数据并将“ - ”替换为“/".
string = replace(string, "-", "/")
然后组装它:
string = "[" & string & "]" & "[Money],"
现在循环数据并在循环中逐个编辑;)希望这有帮助!