Thread: Cells format
View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Cells format

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

--
Regards,
Tom Ogilvy

"fragher75 " wrote in message
...
Hi.

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

Can you help me?


---
Message posted from http://www.ExcelForum.com/