Formatting and Ignore error
Hi Csaba -
1) Application.ErrorCheckingOptions.NumberAsText = False
Note that the above statement turns off the NumberAsText rule for the whole
application (so error checking for "numbers as text" is totally disabled and
remains so until turned back on). This can also be done via menu option
[Tools], [Options], [ErrorChecking tab]...
2) The following procedure builds a custom format for integers by adding the
characters "_._1_1" to the existing general format of any integers in your
column. So, after running, you can examine the format (and modify if
desired) by checking the format manually (Format, Cells, Tab=Number,
Category=Custom...).
Sub Csaba02()
Set rng = Range("A2:A100") '<--- change to suit
'Initialize cell alignments to a common starting point
'(remove existing number formats and alignments)
With rng
.NumberFormat = "General"
.HorizontalAlignment = xlGeneral
End With
For Each itm In rng
If Int(itm.Value) - itm.Value < 0.005 Then
itm.Value = Int(itm.Value) 'truncates 67.001 to integer
itm.NumberFormat = itm.NumberFormat & "_._1_1"
Else
itm.NumberFormat = "0.00"
End If
Next 'itm
End Sub
---
Jay
"Csaba Gabor" wrote:
Two questions:
1) Removing error indicator: If I insert a long numeric value into a
cell that has been formatted as a string (or I prefix it with an
apostrophe: e.g. '1234567890123), then the cell gets a little green
triangle at its upper left. To remove this triangle, I select the
cell, then click on the dropdown to the left of the cell and select:
Ignore error. However, the macro recorder does not record anything
for this action. Question, how do I programatically remove the little
green triangle from the cell?
2) Formatting with alignment: I've got a column of numbers. If they
are not integers, I would like two decimals displayed (e.g. 5.3 should
display 5.30; presumably 5.809 would display 5.81 truncation is OK,
too). If they are integers, however, I would like them aligned with
the units digit of the values displaying decimals. (ie. displaying 6
should have the 6 should be directly below the digit 5 of 5.30, but
there should be no .00 following the 6). Is there a format which
would do this?
Thanks for any tips,
Csaba Gabor from Vienna
Excel 2003 on Win XP Pro
|