0 votes
in VBA by Beginner (21 points)
        Sheets("217").Range("$G$2:$G" & LastRow).Select
        Selection.Replace What:="", Replacement:=Cells(Active.row, 6).Value, LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False

I am trying to find and replace the currently selected cell value with that of another cell on the same current row.

I have added the code that I thought would work but it hasn't. Anyone got any ideas on how I could go about doing this?

 

2 Answers

+1 vote
ago by Skilled (279 points)
edited ago by
 
Best answer

Suggest you avoid using "Select". 

Public Sub ReplaceAll()
Dim lngLastRow As Long

    With Sheets(1)
        lngLastRow = .Range("G" & Rows.Count).End(xlUp).Row
        .Range("G2:G" & lngLastRow).Replace what:=ActiveCell.Value, replacement:=.Range("F" & ActiveCell.Row).Value
    End With
    
End Sub

HTH. 

0 votes
ago by Beginner (21 points)
                               
        Sheets("217").Range("$G$2:$G" & LastRow).Select
        Selection.Replace What:="", Replacement:=Range("F" & (ActiveCell.row)).Value, LookAt:=xlPart, 
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False

Never mind answered my own question, used coding above.

Welcome to wellsr Q&A
wellsr Q&A is the VBA and Python programming community that rewards you for learning how to code.

Getting Started
Register
VBA Cheat Sheets (On Sale Now)

Earn free prizes for asking VBA and Python questions and for answering questions asked by others in our community.

What makes us different?
Our points system rewards you with a chance for free gifts based on the quality of your questions and answers. All you have to do is post and you could get rewarded, like these members:

runfunke $10 Amazon Gift Card
coolag $10 Amazon Gift Card
Siew Hun $10 Amazon Gift Card

So, why don't you join us? It really is an encouraging way to motivate members in our VBA and Python community.

Register

For more programming tips visit the VBA Tutorials Blog and the Python Tutorials Blog.

...