This may be too simple and understanding of your problem, but as an alternative to using VBA, could you hide the z's column (lets call it column C on the spreadsheet), then in column D put a formula along the lines of:
=IF(B2="a",TEXT(C2,"#.##"),TEXT(C2,"#.###"))
Nested IF's would allow more...