Cells format

  • Thread starter Thread starter fragher75
  • Start date Start date
F

fragher75

Hi.

I have a problem. When I import a .txt file create by an accountin
software, where there are negative numbers value in this format (fo
example 150-), after the importation those numbers have a text forma
and I can't sum them with the other numbers. I have a custom forma
(#.##0;#.##0-) but I can't apply it after the importation.

Can you help me
 
Hi
try using 'Data - Text to columns' to convert the negative
numbers to rela values
 
In most cases, a format does not affect what is stored in the cell. Excel
sees 150- as a string. Therefore, you number format has no effect. You can
use a macro to fix them

Select the cells and run a macro like this

Sub PostfixNegative()
Dim rng as Range, cell as Range
if selection.count > 1 then
On Error Resume Next
set rng = selection.specialCells(xlConstants,xlTextValues)
On Error goto 0
else
set rng = selection
End if
if not rng is nothing then
for each cell in rng
if Right(trim(cell.value),1) = "-" then
Cell.Value = cdbl(cell.Value)
end if
Next
End if
End Sub
 
Doesn't work in Excel 2000 or Excel 97 at least. (as far as reevaluating
the cells. If you meant to separate the number from the negative sign, that
would be different).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top