This code searches for a lookup value (Worksheet "Price", Column B13:B31) from the table array in (Worksheet "Sheet1", Column A4:Z10000).
Can this be done in a simpler or shorter way?
Please find my code below;
Sub Lookup1()
Dim r, i As Long, rngLU As Range, j As Long
Dim price, descr As String
i = 13
j = 14
k = 15
l = 16
m = 17
n = 18
o = 19
p = 20
q = 21
g = 22
s = 23
t = 24
u = 25
v = 26
w = 27
x = 28
y = 29
Z = 30
h = 31
Set rngLU = Sheet4.Range("A4:A120000")
With Sheet1
If .Range("B" & i).Value2 > 1 Then
r = Application.Match(.Range("B" & i).Value2, rngLU, 0)
If IsError(r) Then
descr = "Please write manually the Item Description in Column K -->"
price = "#N/A"
Else
descr = rngLU.Cells(r, 3) ' col C
price = rngLU.Cells(r, 4) ' col D
End If
End If
.Cells(i, "C") = descr
.Cells(i, "H") = price
End With
With Sheet1
If .Range("B" & j).Value2 > 1 Then
r = Application.Match(.Range("B" & j).Value2, rngLU, 0)
If IsError(r) Then
descr = "Please write manually the Item Description in Column K -->"
price = "#N/A"
Else
descr = rngLU.Cells(r, 3) ' col C
price = rngLU.Cells(r, 4) ' col D
End If
End If
.Cells(j, "C") = descr
.Cells(j, "H") = price
End With
With Sheet1
If .Range("B" & k).Value2 > 1 Then
r = Application.Match(.Range("B" & k).Value2, rngLU, 0)
If IsError(r) Then
descr = "Please write manually the Item Description in Column K -->"
price = "#N/A"
Else
descr = rngLU.Cells(r, 3) ' col C
price = rngLU.Cells(r, 4) ' col D
End If
End If
.Cells(k, "C") = descr
.Cells(k, "H") = price
End With
With Sheet1
If .Range("B" & l).Value2 > 1 Then
r = Application.Match(.Range("B" & l).Value2, rngLU, 0)
If IsError(r) Then
descr = "Please write manually the Item Description in Column K -->"
price = "#N/A"
Else
descr = rngLU.Cells(r, 3) ' col C
price = rngLU.Cells(r, 4) ' col D
End If
End If
.Cells(l, "C") = descr
.Cells(l, "H") = price
End With
With Sheet1
If .Range("B" & m).Value2 > 1 Then
r = Application.Match(.Range("B" & m).Value2, rngLU, 0)
If IsError(r) Then
descr = "Please write manually the Item Description in Column K -->"
price = "#N/A"
Else
descr = rngLU.Cells(r, 3) ' col C
price = rngLU.Cells(r, 4) ' col D
End If
End If
.Cells(m, "C") = descr
.Cells(m, "H") = price
End With
With Sheet1
If .Range("B" & n).Value2 > 1 Then
r = Application.Match(.Range("B" & n).Value2, rngLU, 0)
If IsError(r) Then
descr = "Please write manually the Item Description in Column K -->"
price = "#N/A"
Else
descr = rngLU.Cells(r, 3) ' col C
price = rngLU.Cells(r, 4) ' col D
End If
End If
.Cells(n, "C") = descr
.Cells(n, "H") = price
End With
With Sheet1
If .Range("B" & o).Value2 > 1 Then
r = Application.Match(.Range("B" & o).Value2, rngLU, 0)
If IsError(r) Then
descr = "Please write manually the Item Description in Column K -->"
price = "#N/A"
Else
descr = rngLU.Cells(r, 3) ' col C
price = rngLU.Cells(r, 4) ' col D
End If
End If
.Cells(o, "C") = descr
.Cells(o, "H") = price
End With
With Sheet1
If .Range("B" & p).Value2 > 1 Then
r = Application.Match(.Range("B" & p).Value2, rngLU, 0)
If IsError(r) Then
descr = "Please write manually the Item Description in Column K -->"
price = "#N/A"
Else
descr = rngLU.Cells(r, 3) ' col C
price = rngLU.Cells(r, 4) ' col D
End If
End If
.Cells(p, "C") = descr
.Cells(p, "H") = price
End With
With Sheet1
If .Range("B" & q).Value2 > 1 Then
r = Application.Match(.Range("B" & q).Value2, rngLU, 0)
If IsError(r) Then
descr = "Please write manually the Item Description in Column K -->"
price = "#N/A"
Else
descr = rngLU.Cells(r, 3) ' col C
price = rngLU.Cells(r, 4) ' col D
End If
End If
.Cells(q, "C") = descr
.Cells(q, "H") = price
End With
With Sheet1
If .Range("B" & g).Value2 > 1 Then
r = Application.Match(.Range("B" & g).Value2, rngLU, 0)
If IsError(r) Then
descr = "Please write manually the Item Description in Column K -->"
price = "#N/A"
Else
descr = rngLU.Cells(r, 3) ' col C
price = rngLU.Cells(r, 4) ' col D
End If
End If
.Cells(g, "C") = descr
.Cells(g, "H") = price
End With
With Sheet1
If .Range("B" & s).Value2 > 1 Then
r = Application.Match(.Range("B" & s).Value2, rngLU, 0)
If IsError(r) Then
descr = "Please write manually the Item Description in Column K -->"
price = "#N/A"
Else
descr = rngLU.Cells(r, 3) ' col C
price = rngLU.Cells(r, 4) ' col D
End If
End If
.Cells(s, "C") = descr
.Cells(s, "H") = price
End With
With Sheet1
If .Range("B" & t).Value2 > 1 Then
r = Application.Match(.Range("B" & t).Value2, rngLU, 0)
If IsError(r) Then
descr = "Please write manually the Item Description in Column K -->"
price = "#N/A"
Else
descr = rngLU.Cells(r, 3) ' col C
price = rngLU.Cells(r, 4) ' col D
End If
End If
.Cells(t, "C") = descr
.Cells(t, "H") = price
End With
With Sheet1
If .Range("B" & u).Value2 > 1 Then
r = Application.Match(.Range("B" & u).Value2, rngLU, 0)
If IsError(r) Then
descr = "Please write manually the Item Description in Column K -->"
price = "#N/A"
Else
descr = rngLU.Cells(r, 3) ' col C
price = rngLU.Cells(r, 4) ' col D
End If
End If
.Cells(u, "C") = descr
.Cells(u, "H") = price
End With
With Sheet1
If .Range("B" & v).Value2 > 1 Then
r = Application.Match(.Range("B" & v).Value2, rngLU, 0)
If IsError(r) Then
descr = "Please write manually the Item Description in Column K -->"
price = "#N/A"
Else
descr = rngLU.Cells(r, 3) ' col C
price = rngLU.Cells(r, 4) ' col D
End If
End If
.Cells(v, "C") = descr
.Cells(v, "H") = price
End With
With Sheet1
If .Range("B" & w).Value2 > 1 Then
r = Application.Match(.Range("B" & w).Value2, rngLU, 0)
If IsError(r) Then
descr = "Please write manually the Item Description in Column K -->"
price = "#N/A"
Else
descr = rngLU.Cells(r, 3) ' col C
price = rngLU.Cells(r, 4) ' col D
End If
End If
.Cells(w, "C") = descr
.Cells(w, "H") = price
End With
With Sheet1
If .Range("B" & x).Value2 > 1 Then
r = Application.Match(.Range("B" & x).Value2, rngLU, 0)
If IsError(r) Then
descr = "Please write manually the Item Description in Column K -->"
price = "#N/A"
Else
descr = rngLU.Cells(r, 3) ' col C
price = rngLU.Cells(r, 4) ' col D
End If
End If
.Cells(x, "C") = descr
.Cells(x, "H") = price
End With
With Sheet1
If .Range("B" & y).Value2 > 1 Then
r = Application.Match(.Range("B" & y).Value2, rngLU, 0)
If IsError(r) Then
descr = "Please write manually the Item Description in Column K -->"
price = "#N/A"
Else
descr = rngLU.Cells(r, 3) ' col C
price = rngLU.Cells(r, 4) ' col D
End If
End If
.Cells(y, "C") = descr
.Cells(y, "H") = price
End With
With Sheet1
If .Range("B" & Z).Value2 > 1 Then
r = Application.Match(.Range("B" & Z).Value2, rngLU, 0)
If IsError(r) Then
descr = "Please write manually the Item Description in Column K -->"
price = "#N/A"
Else
descr = rngLU.Cells(r, 3) ' col C
price = rngLU.Cells(r, 4) ' col D
End If
End If
.Cells(Z, "C") = descr
.Cells(Z, "H") = price
End With
With Sheet1
If .Range("B" & h).Value2 > 1 Then
r = Application.Match(.Range("B" & h).Value2, rngLU, 0)
If IsError(r) Then
descr = "Please write manually the Item Description in Column K -->"
price = "#N/A"
Else
descr = rngLU.Cells(r, 3) ' col C
price = rngLU.Cells(r, 4) ' col D
End If
End If
.Cells(h, "C") = descr
.Cells(h, "H") = price
End With
Call ClearRows
End Sub