相关疑难解决方法(0)

使用替换或替换更改日期格式

我正在从一个excel文件中读取数据并将数据写入另一个excel文件.

我的问题是源具有格式的日期,dd.mm.yyyy目标必须具有格式dd-mm-yyyy.

所以我搜索了SO并找到了这个答案用一个字符串替换另一个字符,这表明我可以使用substitute.

所以我尝试了这段代码:

For r = 1 To 10 
    myOutputSheet.Cells(6+r, 1).Value  = myInputSheet.Cells(r, 1).Value 'Date
    myOutputSheet.Cells(6+r, 1).Value  = substitute(myOutputSheet.Cells(6+r, 1), ".", "-")
Next
Run Code Online (Sandbox Code Playgroud)

它给出了错误:

Microsoft VBScript runtime error: Type mismatch: 'substitute'
Run Code Online (Sandbox Code Playgroud)

我如何更改.-

更新

我也尝试过这个:

For r = 1 To 10 
    myOutputSheet.Cells(6+r, 1).Value  = myInputSheet.Cells(r, 1).Value 'Date
    replace(myOutputSheet.Cells(6+r, 1), 2, 1, "-")
    replace(myOutputSheet.Cells(6+r, 1), 4, 1, "-")
Next
Run Code Online (Sandbox Code Playgroud)

但是这给出了错误:

Microsoft VBScript compilation error: Cannot use parentheses when calling …
Run Code Online (Sandbox Code Playgroud)

excel vba

2
推荐指数
1
解决办法
1996
查看次数

标签 统计

excel ×1

vba ×1