+ Reply to Thread
Results 1 to 4 of 4

Macro to find all specific values in column and replace adjacent cell values

Hybrid View

  1. #1
    Registered User
    Join Date
    02-01-2012
    Location
    Denver, CO
    MS-Off Ver
    Excel 2003
    Posts
    2

    Macro to find all specific values in column and replace adjacent cell values

    Hello,

    Via macro, is there a way to find all specific values within a column, then replace the right adjacent cell values of each value found with the values in the cell directly above the adjacent cells?

    For example, I have attached a spreadsheet with four product values in Column B (Hardware, SW, Installation, Shipping). I would like to find all “SW” items in column B, and replace the Date in column C with the Date of the “Hardware” item in the row directly above the “SW” item. I would then like to repeat this same action for “Installation” and “Shipping” rows.

    The data I receive will change daily, and the SW, Installation, and Shipping lines would always need to be updated with the date as the HW line directly above.

    Thanks for taking a look!
    Attached Files Attached Files
    Last edited by dblock02; 02-11-2012 at 10:59 PM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Macro to find all specific values in column and replace adjacent cell values

    Is this what you mean?
    Option Explicit
    
    Sub SW()
        Dim rRng As Range
        Dim rCl As Range
    
        Set rRng = Range(Cells(1, 2), Cells(Rows.Count, 2).End(xlUp))
    
        For Each rCl In rRng
            If rCl.Value = "SW" Then rCl.Offset(, 1).Value = rCl.Offset(-1, 1).Value
        Next rCl
    End Sub
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    08-16-2012
    Location
    Ghana
    MS-Off Ver
    Excel 2010
    Posts
    1

    Re: Macro to find all specific values in column and replace adjacent cell values

    @royUK. Can you please explain your code step by step? I'm faced with a similar challenge and I want to adapt your code to solve my problem.

    So please, if you can explain what each step of your code does, especially, rRng, rCl and the rRng setting.

    Thanks

  4. #4
    Registered User
    Join Date
    02-01-2012
    Location
    Denver, CO
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Macro to find all specific values in column and replace adjacent cell values

    Perfect!!!!! Thank you very much royUK!!!

+ 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