Check values in cells and replace them if they are the same value

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Need some help to make a macro that check value in B3 against values in D3,
F3, H3 if any of the values are the same as in B3 it shall be replaced with
value in A3.

Then it shall go to B4 and do the same sheck With D4 , F4 and H4 untill it
reach the last entry inn B collone

Finn
 
Does it make any difference if we change B3 or change the cell that matches
its value?
 
Does it make any difference if we change B3 or change the cell that matches
its value?

This should work. (It hasn't been tested)

Option Explicit
Sub macro1()
Dim a
Dim counter
Dim aVal

counter = Range("A1").CurrentRegion.Rows.Count

For a = 1 To counter
aVal = Range("A" & a).Value

If Range("B" & a).Value = Range("D" & a).Value Then
Range("D" & a).Value = aVal
End If

If Range("B" & a).Value = Range("F" & a).Value Then
Range("F" & a).Value = aVal
End If

If Range("B" & a).Value = Range("H" & a).Value Then
Range("H" & a).Value = aVal
End If
Next

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top