Data entry work, using VBA

Source: Internet
Author: User

VBA Usage Tips

Today, the tutor gave me three tables, a table contains two columns of data, doctor's name, ID card. Table B contains 3 columns of data, Master's name, identity card, mentor name, C table containing a list of data, PhD and master's names. Then ask me to enter the corresponding ID in the second column of table C according to the name appearing in C. At first, I thought about it, and it would be an easy thing to do if Dr. A's name sequence, the b master name sequence, and the sequence of names in the C table match. It turned out to be a sad reminder. The name in the C table is a mixture of masters and PhDs, completely indistinguishable from open! I tried many methods, but I didn't have any homework, so I tried to use VBA.

First of all, I will first put together A and B table! Get D table, two columns of data: Name, ID card.

Then, copy the names from table C to the third column in table D.

Next, we press ALT + F11. Because, I was operating under the Sheet1.

, select Sheet1

We typed in the code, you can modify the corresponding column according to your own business!

Subsample ()DimMyCell asRangeDimMyresutl asRange forn =1  to  -    form =1  to  -   IfCells (M,"A"). Value = Cells (n,"C"). Value ThenCells (N,"C"). Value = Cells (M,"B"). ValueEnd If   Next   NextEnd Sub

where N,m table D table The length of the first column and the length of the third column of table D.

Ha ha! Finally, everyone press the "Run" button on the line!

In addition, there is a small detail, if you enter the ID card, you can because the number of digits is too long, Excel default cell format is normal, will result in discarding the last three bits!

The workaround is to: Format the cell as text!

I wish you all a smooth work!

2014-12-18

Data entry work, using VBA

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.