ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Adding leading zeroes to selected alphanumeric cells (https://www.excelbanter.com/excel-programming/398170-adding-leading-zeroes-selected-alphanumeric-cells.html)

[email protected]

Adding leading zeroes to selected alphanumeric cells
 
Can anyone tell me why this only works on the FIRST cell of a
selection rather than ALL selected cells?

Sub fixID()
For Each rng In Selection
rng.NumberFormat = "@"
rng.Value = Right("000000" & rng.Value, 6)
Exit Sub
Next
End Sub

Pardon my ignorance.


[email protected]

Adding leading zeroes to selected alphanumeric cells
 
On Sep 26, 11:01 am, "
wrote:
Can anyone tell me why this only works on the FIRST cell of a
selection rather than ALL selected cells?

Sub fixID()
For Each rng In Selection
rng.NumberFormat = "@"
rng.Value = Right("000000" & rng.Value, 6)
Exit Sub
Next
End Sub

Pardon my ignorance.


nevermind: I read my post and saw the "exit sub" --oops



All times are GMT +1. The time now is 01:58 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com