Effect preview:
Converted to a date format:
Extract from ID date of birth:
Example code:
1. Convert to date format
Method 1:
Subzhuanhuadate () Dim I as Integer fori =2 toSheet1.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)) NextEnd Sub
Method 2:
SubZhuanhua ()DimI as Integer' Use the WITH statement to complete withSheet1 fori =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)) NextEnd withEnd Sub
2. Extracting birthdays from your ID card
Method 1:
SubTiqushengri ()DimI as Integer fori =2 toSheet2.range ("a65536"). End (Xlup). Row Sheet2.range ("b"& i) =DateSerial(Mid(Sheet2.range ("a"& i),7,4),Mid(Sheet2.range ("a"& i), One,2),Mid(Sheet2.range ("a"& i), -,2)) NextEnd Sub
Method 2:
SubTiqushengri2 ()DimI as Integer withSheet2 fori =2 to. Range ("a65536"). End (Xlup). Row. Range ("b"& i) =DateSerial(Mid(. Range ("a"& i),7,4),Mid(. Range ("a"& i), One,2),Mid(. Range ("a"& i), -,2)) NextEnd withEnd Sub
The use of functions in VBA for teacher Yang's Classroom _vba Learning Tutorial