Tim Hanson
Member
Hi,
I am struggling to create the nested loop my first.
I need to assign the ID value to the cell in the source column when it matches the cell value in the email column.
i.e from the email column the first cell value is bobjohnson@email.com his ID value is 0 I need to find all the cells with bobjohnson@email.com in the Source column and assign them 0
I know my code is a mish-mash of stuff, but after hour of tiring am hoping for some help.
Thank you
Original File
Results File
I am struggling to create the nested loop my first.
I need to assign the ID value to the cell in the source column when it matches the cell value in the email column.
i.e from the email column the first cell value is bobjohnson@email.com his ID value is 0 I need to find all the cells with bobjohnson@email.com in the Source column and assign them 0
I know my code is a mish-mash of stuff, but after hour of tiring am hoping for some help.
Thank you
Code:
Sub Source()
Application.ScreenUpdating = False
Dim i As Integer
Dim lrow As Long
Dim Myfind As String
Dim Idvalue As String
Dim firstaddress As String
Dim c
lrow = Sheets("Sheet2").Range("C65336").End(xlUp).Row
With Worksheets(2)
For i = 1 To lrow
Myfind = Cells(i, 3).Text
Idvalue = Cells(i, 2).Value
Set c = Range("A:A").Find(Myfind, LookIn:=xlValues)
If Not c Is Nothing Then
firstaddress = c.Address
Do
Range("MyFind").Select
ActiveCell.FormulaR1C1 = Idvalue
Set c = Range("A:A").FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstaddress
End If
Next i
End With
End Sub
Original File
Code:
email ID Source
bobjohnson@email.com 0 pollypots@email.com
bobjohnson@email.com 0 juanalvarez@email.com
frankcarpet@email.com 1 bettysue@email.com
juanalvarez@email.com 2 bobjohnson@email.com
juanalvarez@email.com 2 bettysue@email.com
sallybersong@email.com 3 Juanalvarez@email.com
sallybersong@email.com 3 yaraflowers@email.com
pollypots@email.com 4 yaraflowers@email.com
yaraflowers@email.com 5 juanalvarez@email.com
yaraflowers@email.com 5 pollypots@email.com
yaraflowers@email.com 5 bobjohnson@email.com
yaraflowers@email.com 5 bettysue@email.com
bettysue@email.com 6 yaraflowers@email.com
Results File
Code:
email ID Source
bobjohnson@email.com 0 4
bobjohnson@email.com 0 2
frakkcarpet@email.com 1 6
juanalvarez@email.com 2 0
juanalvarez@email.com 2 6
sallybersong@email.com 3 2
sallybersong@email.com 3 5
pollypots@email.com 4 5
yaraflowers@email.com 5 2
yaraflowers@email.com 5 4
yaraflowers@email.com 5 0
yaraflowers@email.com 5 6
bettysue@email.com 6 5
Last edited by a moderator: