The use of functions in VBA for teacher Yang's Classroom _vba Learning Tutorial

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.