标签:技术分享 16px amp vba size str 提取 .com integer
效果预览图:
转换为日期格式的效果图:
从身份证中进行提取出生日期:
示例代码:
1. 转换为日期格式
方法1:
Sub zhuanhuaDate() Dim i AS Integer For i = 2 To Sheet1.Range("a65536").End(xlUp).Row Sheet1.Range("b" & i) = DateSerial(Left(Sheet1.Range("a" & i), 4), Mid(Sheet1.Range("a" & i), 5, 2), Right(.Range("a" & i), 2)) Next End Sub
方法2:
Sub zhuanhua() Dim i As Integer ‘使用with 语句完成 With Sheet1 For i = 2 To .Range("a65536").End(xlUp).Row .Range("b" & i) = DateSerial(Left(.Range("a" & i), 4), Mid(.Range("a" & i), 5, 2), Right(.Range("a" & i), 2)) Next End With End Sub
2.提取身份证中的生日
方法1:
Sub tiqushengri() Dim i As Integer For i = 2 To Sheet2.Range("a65536").End(xlUp).Row Sheet2.Range("b" & i) = DateSerial(Mid(Sheet2.Range("a" & i), 7, 4), Mid(Sheet2.Range("a" & i), 11, 2), Mid(Sheet2.Range("a" & i), 13, 2)) Next End Sub
方法2:
Sub tiqushengri2() Dim i As Integer With Sheet2 For i = 2 To .Range("a65536").End(xlUp).Row .Range("b" & i) = DateSerial(Mid(.Range("a" & i), 7, 4), Mid(.Range("a" & i), 11, 2), Mid(.Range("a" & i), 13, 2)) Next End With End Sub
标签:技术分享 16px amp vba size str 提取 .com integer
原文地址:https://www.cnblogs.com/xiaoxiao5016/p/9062418.html