Loops, ranges and VLookup
Bernie, thanks so much for the reply, i have this...
Dim x As Integer
Dim FinalRow As Long
FinalRow = Cells(Rows.Count, 4).End(xlUp).Row
For x = 2 To FinalRow
If Cells(x, 6).Value = "" Then
Cells(x, 6).Formula = "=IF(ISERROR(VLOOKUP(" & Cells(x,
4).Address & _
",ProjectList,3,False)),VLOOKUP(" & Cells(x, 4).Address &
_
",AliasList,2,False),VLOOKUP(" & Cells(x, 4).Address & _
",ProjectList,3,False))"
End If
Next x
However, i am getting #N/A in some of the fields and I know for a fact
that there are matches in the vlookup ranges..
It seems like this is such the better solution, but i was also working
on this one too... out of pieces of code i found...
I am using this and it works... but would like the shorter solution,
like yours...
'////////////////////////////////////////////////////////////////
Dim x, FinalRow, rw As Long
Dim w As Worksheet
Dim s, r
Dim rng As Range
FinalRow = Cells(Rows.Count, 4).End(xlUp).Row
rw = Sheets("Project").Cells(65500, 1).End(xlUp).Row
Set w = Sheets("Project")
Dim MyColumn As String, Here As String
Set rng = w.Range("A2:B" & rw)
For x = 2 To FinalRow
Cells(x, 6).Select
s = Cells(x, 4).Value
If Cells(x, 6).Value = "" Then
For Each r In rng
If r.Value = s Then
'Cells(x, 6).Value = r.Value
Cells(x, 7).Value = r.Address
Cells(x, 6).Formula = "=VLOOKUP(" & Cells(x, 4).Address &
_
", ProjectList,3,True)"
Here = r.Address
MyColumn = Mid(Here, InStr(Here, "$") + 1, InStr(2, Here,
"$") - 2)
If MyColumn = "B" Then
'MsgBox "my column = B"
Cells(x, 4).Clear
Cells(x, 4).Value = r.Offset(0, -1).Value
Cells(x, 6).Formula = "=VLOOKUP(" & Cells(x, 4).Address
& _
", ProjectList,3,True)"
End If
Exit For
End If
Next r
End If
Next x
'///////////////////////////////////////////////////////////////
|