+ Reply to Thread
Results 1 to 19 of 19

how to change the code to do find the value and replace value

  1. #1
    Forum Contributor
    Join Date
    02-12-2010
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    134

    how to change the code to do find the value and replace value

    hi
    i have this code from this forum but i need to change to do the following
    to change the value of column
    H = c*.88,
    I =c*0.12,
    J=sum(H:I)
    on same row which changed by input value

    PHP Code: 
    Sub changevalue2()
        
    Dim r As Rangerng As Ranger1 As Ranger2 As RangeAs StringAs String



        Set r 
    Range("G5"Range("G580").End(xlUp))

        
    r.Offset(08).ClearContents

        s 
    InputBox("What to find and change?")
        
    InputBox("change with")

        
    With Range("G5")
            .
    AutoFilter Field:=7Criteria1:=s

            On Error Resume Next

            Set rng 
    r.Cells.SpecialCells(xlCellTypeVisible)    'if no items found

            If rng Is Nothing Then
                MsgBox "No records found"
                .AutoFilter
                Exit Sub
            End If
            r = c                             '
    <----- its working perfectly as per my  need 
            r1
    .Offset(08) = 0.88     '<----- not working 
            r2.Offset(0, 9) = c * 0.12      '
    <----- not working 
           
            
    .AutoFilter
        End With


    End Sub 
    thanks for help
    Last edited by jay11; 07-11-2010 at 05:07 PM.

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: how to change the code to do find the value and replace value

    Hi jay11
    I'd try changing these lines of code
    Please Login or Register  to view this content.
    to this
    Please Login or Register  to view this content.
    Not tested but you have no reference to r1 or r2. Your reference is to r.
    John
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Forum Contributor
    Join Date
    02-12-2010
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    134

    Re: how to change the code to do find the value and replace value

    hi John
    i change as u directed but not change in value in column H,I,J
    i also try to change the range
    from this
    Please Login or Register  to view this content.
    to

    Please Login or Register  to view this content.
    then it change all column with same value as G
    any idea what i am doing wrong?

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: how to change the code to do find the value and replace value

    Hi jay11
    Without seeing your actual workbook, it's difficult to say. However, there is no line of code that changes the value of either H or I. If you're expecting this code
    Please Login or Register  to view this content.
    to do it, you're off by several columns. If this code is indeed designed to change the values of H and I, it should read
    Please Login or Register  to view this content.
    If this is what you're trying to accomplish, reverse the change you made to Set r and make the reference change illustrated above. Otherwise, post a copy of what you have and what you'd like it to be and I'll see if I can help.
    John

    PS: By the way, this also changes I
    Please Login or Register  to view this content.
    What are your intentions here?
    Last edited by jaslake; 07-10-2010 at 06:25 PM.

  5. #5
    Forum Contributor
    Join Date
    02-12-2010
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    134

    Re: how to change the code to do find the value and replace value

    hi john hear is the sheet "Names" with small data sample
    Attached Files Attached Files

  6. #6
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: how to change the code to do find the value and replace value

    Hi Jay11
    I'm still a little unclear what you wish to do (your sample file included no formulas). Try this code
    Please Login or Register  to view this content.
    and see if we're approaching what it is you wish to accomplish.
    Let me know of issues.
    John
    Attached Files Attached Files

  7. #7
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: how to change the code to do find the value and replace value

    Hi Jay11
    I forgot to point out that I changed this line of code
    Please Login or Register  to view this content.
    I changed it to this
    Please Login or Register  to view this content.
    That eliminates this issue
    then it change all column with same value as G
    John

  8. #8
    Forum Contributor
    Join Date
    02-12-2010
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    134

    Re: how to change the code to do find the value and replace value

    thanks buddy
    it work great but can u change the code so it work only on the "Names" sheet only
    since there r so many sheet in the wb
    i try to change like this but it did not work

    Please Login or Register  to view this content.
    so i can run this code from the different sheet but it only change in to 'Names' sheet

    thanks for your help

  9. #9
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: how to change the code to do find the value and replace value

    Hi Jay11
    Try this code. It can be executed from any worksheet
    Please Login or Register  to view this content.
    Let me know of issues.
    John

  10. #10
    Forum Contributor
    Join Date
    02-12-2010
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    134

    Re: how to change the code to do find the value and replace value

    hi john
    thanks it work great
    thanks for all help
    u the man

  11. #11
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: how to change the code to do find the value and replace value

    Hi jay11
    Don't mark it as solved just yet. I found a glitch. Will get back to you ASAP.
    John

  12. #12
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: how to change the code to do find the value and replace value

    Hi jay11
    Try this revised code
    Please Login or Register  to view this content.
    John

  13. #13
    Forum Contributor
    Join Date
    02-12-2010
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    134

    Re: how to change the code to do find the value and replace value

    hi John
    what was the glitch in the code ?it seems to me work fine

  14. #14
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: how to change the code to do find the value and replace value

    Hi jay11

    If you still have the old code loaded, enter 999.99 in s = InputBox("What to find and change?") and 888.88 in c = InputBox("change with") and see what happens.

    The revised code fixes that.

    John

  15. #15
    Forum Contributor
    Join Date
    02-12-2010
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    134

    Re: how to change the code to do find the value and replace value

    hi John
    thanks this new code is changing value and work .but now it add new records at last row
    here i am attaching the wb with both code and commented last row.
    thanks for helping otherwise i be in trouble.
    Attached Files Attached Files

  16. #16
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: how to change the code to do find the value and replace value

    Hi jay11
    I think this may have it. Sorry about that.
    Please Login or Register  to view this content.
    Let me know of issues.
    John
    Attached Files Attached Files

  17. #17
    Forum Contributor trucker10's Avatar
    Join Date
    07-22-2009
    Location
    Belgium
    MS-Off Ver
    Excel 2003 / 2007 / 2010 prof +
    Posts
    149

    Re: how to change the code to do find the value and replace value

    Please Login or Register  to view this content.

  18. #18
    Forum Contributor
    Join Date
    02-12-2010
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    134

    Re: how to change the code to do find the value and replace value

    hi John
    this code work great without any prob.
    thank you very much
    also thanks trucker10 for suggestion.

  19. #19
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: how to change the code to do find the value and replace value

    Hi jay11

    I think we've worked this out. If you're happy with the solution, please mark your post as solved. A click on the scales is appreciated if you feel appropriate.

    John

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1