Resize and a question
The check
if right(cell,1)="-" then
should eliminate any problems with headers - cdbl then only looks at cells
containing a "-" as the rightmost character.
cdbl converts this a negative number
? cdbl("231-")
-231
if you having problems, add an isnumeric test
? isnumeric("231-")
True
Dim myRange as Range, Cell as Range
set myRange = Range(Cells(2,10),cells(rows.count,10).End(xlup))
set myRange = myRange.Offset(0,-8).Resize(,9)
for each cell in myRange.SpecialCells(xlConstants,xlTextValues)
if right(cell,1)="-" then
if isnumeric(cell) then
cell.Value = cdbl(cell.value)
end if
end if
Next
--
Regards,
Tom Ogilvy
"a" wrote in message
hlink.net...
Thanks Tom Ogilvy,
Unfortunately - this doesn't work because the csv file has headers in
between the different reports and the "cdbl" doesn't seem to like that.
By the way - why does the function cdbl - which I think means "Change
to a double" work at changing the value with the trailing "-" to a
negative?
As always - thanks for all of your help. The resize part works great
and so now I just need to tinker with your code to get something that
will work with my file.
Thanks again,
Anita
Tom Ogilvy wrote:
Dim myRange as Range, Cell as Range
set myRange = Range(Cells(2,10),cells(rows.count,10).End(xlup))
set myRange = myRange.Offset(0,-8).Resize(,9)
for each cell in myRange.SpecialCells(xlConstants,xlTextValues)
if right(cell,1)="-" then
cell.Value = cdbl(cell.value)
end if
Next
to demonstrate from the immediate window:
set myRange = Range(Cells(2,10),cells(rows.count,10).End(xlup))
? myRange.Address
$J$2:$J$11
? myRange.Offset(0,-6).Resize(,7).Address
$D$2:$J$11
so it processes column 4 to column 10
|