Fine tune a macro that replaces -ve values with 1 in a Range

  • Hi!


    Following macro replaces negative values in the range A2:I30 with 1.


    The macro runs fine when the current active worksheet is same as worksheet Sheet2. However, if the current active worksheet OR workbook is different from Book1.xlsm or Sheet2, the macro either throws error (if run in background through another macro OR simply does not run if run by a button on another Worksheet).


    Can someone please point out what am I missing here.


    Note: Sample file attached.


    Thanks
    Naira

  • Re: Fine tune a macro that replaces -ve values with 1 in a Range


    naira ur missing to give the refrence for the file you want to run....
    the code which you provided will only work on Book1.. i have edited the code have a look


  • Re: Fine tune a macro that replaces -ve values with 1 in a Range


    Quote from ashu1990;733455

    naira ur missing to give the refrence for the file you want to run....
    the code which you provided will only work on Book1.


    Thank for the reply, tested it but your solution doesn't work. It is EXACTLY OPPOSITE to what I want.
    The code needs to run only on Sheet2 of Book1.xlsm NOT on the currently active worksheet.
    In other words, as already pointed out in my original post, I want it to run only on Sheet2 of Book1.xlsm, no matter what is the currently active workbook or worksheet.


    Still waiting for a solution...

  • Re: Fine tune a macro that replaces -ve values with 1 in a Range


    Hi Naira


    I think maybe the dot at beginning


    Code
    .Range("A2:I30")
  • Re: Fine tune a macro that replaces -ve values with 1 in a Range


    HOLYCOW....
    If only all the problems of life could be resolved with a simple missing dot.
    (Thanx... solution works great).

  • Re: Fine tune a macro that replaces -ve values with 1 in a Range


    Quote

    If only all the problems of life could be resolved with a simple missing dot


    Yeah that be good :)

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!