Add leading zeros to number in clipboard


I have a series of numbers ranging from four to seven digits that I need to copy individually and have KM transform them into seven digit numbers with leading zeros if their original digits were less than seven, before pasting individually.

For example

Copy 61745 and paste 0061745
Copy 1347890 and paste 1347890

How would I get KM to do this?

Many thanks

Welcome to the forums :slight_smile:

I'm not sure exactly how you need to implement your macro, but here's a routine that takes the number on the clipboard (note that it assumes it's a number; error checking could be easily added), pads it to seven digits, then puts it back on the clipboard, ready for pasting:

pad number to seven digits.kmmacros (3.3 KB)

Assign it to a hot key, copy a number, launch the macro, then hit paste. Or you could add the Paste step to the macro if you wish.


1 Like

Just noticed a minor issue in the macro: Step two should filter the variable local_theNumber with character count (still to local_howLong). It's filtering the clipboard, but I already set the variable based on the clipboard.


Thanks Rob, that's done it! Thanks for the help and the very kind welcome :smiling_face:


There's a much simpler solution:

Format Copied Number and Paste.kmmacros (21 KB)

Macro screenshot


Ha! I knew there had to be a better way! :slight_smile


1 Like