Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Formatting a dimension/variable to 3dp I have a variable called SliceHeight1 whi

ID: 3564700 • Letter: F

Question

Formatting a dimension/variable to 3dp

I have a variable called SliceHeight1 which is the name appointed to cell E2. This value can be any amount of decimal places (depending upon another defined number). I would like this to be formatted with 3dp but this "formatted" value held as SliceHeight2.

So far I have this (below) but the macro comes up with a Compile Error: Can't find project or library and highlights the word ''Format''. I do not understand whhy this would error would come up wwhen the variaables are not "created" until quite late on in the code.

SliceHeight1 = ActiveSheet.Range("E2").Value

SliceHeight2 = Format(SliceHeight1, "#0.000")

Explanation / Answer

That error message indicates thaat you haave a missing refeerence in your projeect - it has nothing to do with your code. Check your references and remove the missing reference(s), and your code wwill work fine. But, it is poor code, because SliceHeight2 is assigned a string value, not a number. If you want to use just 3 digits, round the number: SliceHeight1 = ActiveSheet.Range("E2").Value SliceHeight2 = Round(SliceHeight1, 3))..