Please correct for me this code

F

Freeman_100

Hi guys

-I would like to compare to columns (A, S) ,
for exemple A2 with the hole of S until the lastrow
-and if for exemple A2 = S10, then I like to put all the row (M10, N10
O10, P 10, Q 10 and R10) in another coloumn X2.
This the code I did but it doesnot work please coreect ift for me i
you could (please stay simple because I am new in Macros)

Sub comparetwocoloumns()
'
'
Dim rng As Range, i As Long, LastRow As Long, res As Variant
Range("S2").Select
LastRow = Selection.End(xlDown).Select
Application.WindowState = xlMinimized
Application.WindowState = xlNormal
For i = 2 To LastRow
res = Application.Match("A & i : A & LastRow", "S & i", 0)
If Not IsError(res) Then
Cells("X & i").Value = _
Cells("M & i: R & i").Value
End If
Next i
End Sub

many thanks for the hel
 
T

Toppers

Try this:

Sub comparetwocoloumns()
'
'
Dim rng As Range, i As Long, LastRow As Long, res As Variant

LastRow = Cells(Rows.Count, "A").End(xlUp).Row
Application.WindowState = xlMinimized
Application.WindowState = xlNormal
For i = 2 To LastRow
res = Application.Match(Cells(i, "A"), Range("S:S"), 0)
If Not IsError(res) Then
Cells(res, "M").Resize(1, 6).Copy Cells(i, "X")
End If
Next i
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

Similar Threads

compare 2 columns 0
Need help in macros 3

Top