I have a column that contains numbers whose leading zeros disappeared thanks to importing into excel. I want to reduce the number of steps this involves so I really don't want to open it in some other program to fix it then import. I'm already running a macro on this for something else, and would love to just add a little bit of script into it to fix this issue. So, I need a macro written that will look at the column with say a header name of ID. If the adjacent column called NAME is any of the following text: apple, orange, banana, blueberry, then add zeros to the beginning of the numbers of column ID so that its total digits is 9. If it does not match criteria, keep it at whatever number is already in the adjacent cell. It would be great if it could just replace the number in the ID column, but I'm okay if it gets moved to another column if that makes it simpler. For example:
[TABLE="width: 261"]
<tbody>[TR]
[TD="class: xl116, width: 87"]ID[/TD]
[TD="class: xl117, width: 87"]NAME[/TD]
[TD="class: xl117, width: 87"]CONVERT TO[/TD]
[/TR]
[TR]
[TD="class: xl116"]1234[/TD]
[TD="class: xl117"]banana[/TD]
[TD="class: xl117"]000001234[/TD]
[/TR]
[TR]
[TD="class: xl116"]45[/TD]
[TD="class: xl117"]cucumber[/TD]
[TD="class: xl117"]45[/TD]
[/TR]
[TR]
[TD="class: xl116"]9876[/TD]
[TD="class: xl117"]orange[/TD]
[TD="class: xl117"]000009876[/TD]
[/TR]
[TR]
[TD="class: xl116"]343[/TD]
[TD="class: xl117"]apple[/TD]
[TD="class: xl117"]000000343[/TD]
[/TR]
</tbody>[/TABLE]
[TABLE="width: 261"]
<tbody>[TR]
[TD="class: xl116, width: 87"]ID[/TD]
[TD="class: xl117, width: 87"]NAME[/TD]
[TD="class: xl117, width: 87"]CONVERT TO[/TD]
[/TR]
[TR]
[TD="class: xl116"]1234[/TD]
[TD="class: xl117"]banana[/TD]
[TD="class: xl117"]000001234[/TD]
[/TR]
[TR]
[TD="class: xl116"]45[/TD]
[TD="class: xl117"]cucumber[/TD]
[TD="class: xl117"]45[/TD]
[/TR]
[TR]
[TD="class: xl116"]9876[/TD]
[TD="class: xl117"]orange[/TD]
[TD="class: xl117"]000009876[/TD]
[/TR]
[TR]
[TD="class: xl116"]343[/TD]
[TD="class: xl117"]apple[/TD]
[TD="class: xl117"]000000343[/TD]
[/TR]
</tbody>[/TABLE]
Last edited: