Search for 'X' in Each Row, If Found Replace with Text in First Cell of that Row

  • Hello,


    I feel like this should be an easy one. I have a spreadsheet that has text in the first cell of each row. Random columns in that row have the letter "X" when that text is reference. I would like to replace the 'X' with the text in the first cell of that row. Then have the code look though the spreadsheet and do that same for each row.


    Text Product1 Product2 Product 3
    Blah Blah Blah   X  
    Do Re Me X   X
    Tic Tac Toe X X  
    Text Product1 Product2 Product 3
    Blah Blah Blah   Blah Blah Blah  
    Do Re Me Do Re Me   Do Re Me
    Tic Tac Toe Tic Tac Toe Tic Tac Toe  
  • Not at my computer at the moment but here’s my very basic shot at it

    Code
    Sub replaceX()
        Dim c as range
        Application.ScreenUpdating = False
        For each c in activesheet.usedrange
            If c.column > 1 and c.row > 1 and ucase(c.value) = "X" Then
                c.value = Cells(c.row, 1).Value
            End If
        Next c
        Application.ScreenUpdating = True
    End Sub
  • Try the attached. Click the button on Sheet1


    This is an alternative method which will be faster especially with a large data set.


    Code assigned to the button:

Participate now!

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