繁体   English   中英

Excel VBA格式的缩写和日期

[英]Excel VBA Format Initials & Date

早上好,

我正在尝试将一组缩写和DOB合并到一个列中,以为每个人创建一个唯一的标识符。 例如,DOB为“ 01/01/2001”的缩写“ JS”应输出JS01012001。 DOB列最初的格式为mm / dd / yyyy。 在进行串联之前,我将其重新格式化为“ mmddyyyy”。 这在DOB列中正确显示。 但是,当我运行宏时(在下面),它在ID列中输出为“ JS01 / 01/2001”。 我正在尝试格式化中可以想到的每种组合,以使其正确输出,但是我仍然没有得到它。 任何帮助将非常感激!

提前致谢!

' Format DOB column (M)
    Columns("M:M").Select
    Selection.NumberFormat = "mmddyyyy"

' Concatenate Initials (L) and DOB (M) columns and output in ID column (N)
    For i = 2 To LastRow
        Cells(i, 14) = Cells(i, 12) & "" & Cells(i, 13)
    Next i

您需要使用以下命令将日期对象转换为VBA中的字符串:

Cells(i, 14) = Cells(i, 12) & Format(Cells(i, 13), "mmddyyyy")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM