VBA code to convert/encode multiple cells

jcocker

New Member
Joined
Jun 2, 2019
Messages
2
[FONT=&quot]I have a worksheet with several 000's rows of data, holding information about patients' visits. Each row holds the information of a single visit.[/FONT]
[FONT=&quot]Each patient can have multiple visits (i.e. appear in multiple rows). The table is sorted by patient name, and the left-most column holds the patient name.[/FONT]
[FONT=&quot]I need to share this sheet with others so that it can analysed, but due to data protection rules I wish to hide the personal information, i.e. patient name, before I do that. [/FONT]
[FONT=&quot]My plan is to keep a master copy of the sheet, just in case. I would like a make a copy of it, with the patient details anonymised, that can then be shared. I would like each patient name to be changed to a sequential number, something like P0001, P0002, etc. The left column of the table will appear like this:[/FONT]
[FONT=&quot]P0001
P0001
P0002
P0003
P0004
P0004
P0005
...[/FONT]

[FONT=&quot]How do I create the encoding automatically please?[/FONT]
[FONT=&quot]Any tips will be much appreciated![/FONT]
 

Some videos you may like

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
40,908
Office Version
365
Platform
Windows
Cross posted https://www.excelforum.com/excel-general/1278120-help-with-encoding-cells-please.html

While we do not prohibit Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules).
This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 

lrobbo314

Well-known Member
Joined
Jul 14, 2008
Messages
2,758
Office Version
365, 2019, 2016
Platform
Windows
Assuming your names begin in cell A1, in B1, put 'P0001'. Then in B2, enter the formula,
Code:
=IF(A2=A1,B1,TEXT(INT(RIGHT(B1,LEN(B1)-1)+1),"P0000"))
then copy it down.
 

lrobbo314

Well-known Member
Joined
Jul 14, 2008
Messages
2,758
Office Version
365, 2019, 2016
Platform
Windows
───────────────────░█▓▓▓█░▇▆▅▄▃▂
──────────────────░█▓▓▓▓▓█░▇▆▅▄▃▂
─────────────────░█▓▓▓▓▓█░▇▆▅▄▃▂
──────────░░░───░█▓▓▓▓▓▓█░▇▆▅▄▃▂ ...
─────────░███░──░█▓▓▓▓▓█░▇▆▅▄▃▂
───────░██░░░██░█▓▓▓▓▓█░▇▆▅▄▃▂
──────░█░░█░░░░██▓▓▓▓▓█░▇▆▅▄▃▂
────░██░░█░░░░░░█▓▓▓▓█░▇▆▅▄▃▂
───░█░░░█░░░░░░░██▓▓▓█░▇▆▅▄▃▂
──░█░░░░█░░░░░░░░█▓▓▓█░▇▆▅▄▃▂
──░█░░░░░█░░░░░░░░█▓▓▓█░▇▆▅▄▃▂
──░█░░█░░░█░░░░░░░░█▓▓█░▇▆▅▄▃▂
─░█░░░█░░░░██░░░░░░█▓▓█░▇▆▅▄▃▂
─░█░░░░█░░░░░██░░░█▓▓▓█░▇▆▅▄▃▂
─░█░█░░░█░░░░░░███▓▓▓▓█░▇▆▅▄▃▂
░█░░░█░░░██░░░░░█▓▓▓▓▓█░▇▆▅▄▃▂
░█░░░░█░░░░█████▓▓▓▓▓█░▇▆▅▄▃▂
░█░░░░░█░░░░░░░█▓▓▓▓▓█░▇▆▅▄▃▂
░█░█░░░░██░░░░█▓▓▓▓▓█░▇▆▅▄▃▂
─░█░█░░░░░████▓▓▓▓██░▇▆▅▄▃▂
─░█░░█░░░░░░░█▓▓██▓█░▇▆▅▄▃▂
──░█░░██░░░██▓▓█▓▓▓█░▇▆▅▄▃▂
───░██░░███▓▓██▓█▓▓█░▇▆▅▄▃▂
────░██▓▓▓███▓▓▓█▓▓▓█░▇▆▅▄▃▂
──────░█▓▓▓▓▓▓▓▓█▓▓▓█░▇▆▅▄▃▂
──────░█▓▓▓▓▓▓▓▓▓▓▓▓▓█░▇▆▅▄▃▂
 

Watch MrExcel Video

Forum statistics

Threads
1,099,503
Messages
5,468,994
Members
406,627
Latest member
IncandenzaH1997

This Week's Hot Topics

Top