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