Help with Vlookup code

G

Gareth

I received the following a few months back and it works just fine, but I
need to amend what it does slighty:

Sub Insertdata()
With Worksheets("sheet1")
Set rng = .Range("C2:C" & .Range("C65536").End(xlUp).Row)
End With
With Worksheets("sheet2")
Set rng1 = .Range("A2:A" & .Range("A65536").End(xlUp).Row)
End With
For Each cell In rng
res = Empty
res = Application.VLookup(cell.Value, rng1.Resize(, 12), 2, 0)
If Not IsError(res) Then
cell.Offset(0, 5).Value = res
cell.Offset(0, 12).Value = Application.VLookup(cell.Value, rng1.Resize(,
12), 12, 0)
End If
Next cell
End Sub

At the moment it puts data from 2 columns on sheet2 onto sheet1, what I want
it to do now is put data from column P on sheet2 into column O on sheet1,
BUT ONLY IF THERE IS NOTHING IN THE CELL.

Thanks in advance.

Gareth
 

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

Top