View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Peter Stone Peter Stone is offline
external usenet poster
 
Posts: 3
Default Compare and replace if equal

Both of Jacob's solutions worked (using either the function or the macro).

Sheeloo's solutions worked sometimes (there were correct replacements mixed
with incorrect repeating replacements).

Thank you both for taking the time to help.

Peter

"Jacob Skaria" wrote:

Hi Peter

Solution 1: Using function (This will provide the value in column D)
Paste this formula in D1...... =VLOOKUP(C1,A$1:B$5,2,FALSE)
Adjust B$5 to the number of rows you have in column A and B
Drag the same formula to the other cells in Column D.

Solution 2: Macro. Launch VBE using Alt+F11. On the left treeview, right
click 'This Workbook' -- Insert-- Module . Paste the below code. Goto
workbook. Paste your values in column C. Run Macro1 from Tools--Macro

If this post helps please click Yes
---------------
Jacob Skaria


Sub Macro1()

Dim intRowA As Integer
Dim intRowC As Integer

intRowC = 1
Do While Range("C" & intRowC) < ""
intRowA = 1
Do While Range("A" & intRowA) < ""
If Range("C" & intRowC) = Range("A" & intRowA) Then
Range("C" & intRowC) = Range("B" & intRowA)
Exit Do
End If
intRowA = intRowA + 1
Loop
intRowC = intRowC + 1
Loop

End Sub