View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
SeanC UK[_3_] SeanC UK[_3_] is offline
external usenet poster
 
Posts: 48
Default Error when changing the sign on numbers

Glad it helped. It's always good to double check things are what you expect,
especially if someone else may be using your code, or amending your
spreadsheets. At some point someone will mess it up!

One reason to start from the bottom is when you are deleting rows. If you
start from the top and are looping through a row counter, you have to
remember not to increment the count if you delete a row. If you start from
the bottom then you never need to remember to do this as you only affect rows
that you've already processed and not the ones above.

There may be other reasons, and sometimes good reasons to start at the top,
but in general a lot of people will work upwards because of this.

Sean.

--
(please remember to click yes if replies you receive are helpful to you)


"tbmarlie" wrote:

On Oct 25, 6:23 pm, Carlo wrote:
hi tbmarlie

have you ever tried it this way:
For k = 1 to Cells(Rows.Count, 10).End(xlUp).Row
Cells(k, 10).Value = Cells(k, 10).Value * -1
Next k

never tried your approach, which starts from behind!
Maybe it works, who knows.

Carlo



"tbmarlie" wrote:
I'm have the following code which is being run as part of a macro.
I'm trying to change the sign on all of the values in this column so
if its a negative, I want it to be positive and vice versa. When I
run my macro, it gives me a "Run-time error '13': Type Mismatch"
message and when I debug, it highlights the 2nd line below in my
code. Whats confusing to me, though, is that it appears to make all
of the changes (that I intended) to all of the cells in my data down
to my very last row. The cells in this column are formated as type
number. There are null cells in the data which get changed to 0.00,
if that means anything. Thanks.


For k = Cells(Rows.Count, "j").End(xlUp).Row To 1 Step -1
Cells(k, "j").Value = Cells(k, "j").Value * -1
Next k- Hide quoted text -


- Show quoted text -


Thanks Sean, That worked. The critical piece that I needed was the
"IsNumeric". I was pretty sure that all of my data was numeric, but
apparently not.

Carlo. Your code worked also (with the "IsNumeric). I just took
someone elses suggestion for starting from the end - I've always
wondered why start at the bottom?

Thanks again.