Need macro able to compare cells content

axioma

New Member
Joined
Jul 24, 2007
Messages
3
Hello forum,

i have a sheet with column A “component code”, and column B “surface”. The sheet has thousands of rows and I usually add rows. I need a procedure able to discover the code I am dialing already exsists and to put automatically in column B the right surface value.
Any help would be greatly appreciated.
Max
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Hi, welcome to the board!

It's not clear to me what you are trying to do, if you are trying to lookup the values from a table, then have a look at the VLOOKUP function. Or are you trying to repeat the values from something already entered in the column?
 
Upvote 0
Hello :) and thank you for your prompt response,

i am just trying to repeat values already entered avoiding the risk of ricalculating complex surfaces area.
 
Upvote 0
You can to try this code

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim valor As Variant, fila As Long

If Target.Column > 1 Then Exit Sub


valor = Target.Value


If valor = Empty Then Exit Sub

Application.EnableEvents = False

fila = Target.Row


If Application.CountIf(Range("A1:A" & fila - 1), valor) >= 1 Then
    Target.Offset(0, 1) = Application.Index(Range("B1:B" & fila - 1), Application.Match(valor, Range("A1:A" & fila - 1), 0))
Application.EnableEvents = True
    End
End If

If Application.CountIf(Range("A" & fila + 1 & ":A65536"), valor) >= 1 Then
    Target.Offset(0, 1) = Application.Index(Range("B" & fila + 1 & ":B65536"), Application.Match(valor, Range("A" & fila + 1 & ":A65536"), 0))
Application.EnableEvents = True
    End
End If

Target.Offset(0, 1).Select
Application.EnableEvents = True

End Sub

GALILEOGALI
 
Upvote 0
EDITED:

Perhaps:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range, d As Range, e As Range
Set d = Intersect(Target, Range("A:A"))
If d Is Nothing Then Exit Sub
Application.EnableEvents = False
    For Each c In d
        Set e = Range("A:A").Find(c, Range("A" & Rows.Count))
        c.Offset(, 1) = e.Offset(, 1)
    Next
Application.EnableEvents = True
End Sub
 
Upvote 0
Hotpepper:

you have proven your solution? If the value to look for is after (underneath) Target, "FIND" finds the first value in Target's position y Target.offset(,1) is empty.
GALILEOGALI
 
Upvote 0
My code will look above Target first, the op wanted to duplicate previously entered entries. If it hasn't been entered because it will only find it at the place that is has just been entered. it will return blank in Column B. Why I ended up leaving it this way is this:

Say you had already entered in Column A, the Values A and C, but copy and paste from a list A, B and C, the A and C values will fill in but the B value would not as that had not been entered yet.

I did assume that previous entries it would be above the latest entry.
 
Upvote 0

Forum statistics

Threads
1,214,521
Messages
6,120,018
Members
448,937
Latest member
BeerMan23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top