Hello,
I have this code. It does exactly what is required even if the range("a2:d15") is not sorted.
Code
On Error GoTo MyErrorHandler:
Dim disname As String
disname = Sheet11.Range("b47")
If Len(disname) > 0 Then
licence = Application.WorksheetFunction.VLookup(disname, Sheet5.Range("a2:d15"), 2, False)
Sheet11.Range("b46").Value = licence
adress = Application.WorksheetFunction.VLookup(disname, Sheet5.Range("a2:d15"), 3, False)
Sheet11.Range("b49").Value = adress
dealer = Application.WorksheetFunction.VLookup(disname, Sheet5.Range("a2:d15"), 4, False)
Sheet11.Range("b44").Value = dealer
Else
End If
Exit Sub
MyErrorHandler:
If Err.Number = 1004 Then
Exit Sub
End If
Display More
Then I have this code that doesn't work properly. It works to a certain point, but where the VLookUp should be returning a result it's doing nothing. The Application.WorksheetFunction.VLookUp looks to my eye to be the same in both lots of code.
Code
Dim serial_text As Range
Set serial_text = Sheet17.Range("b53")
serial_text.NumberFormat = "General"
Dim clear_sheet As Range
Set clear_sheet = Sheet17.Range("b40:b61")
clear_sheet.ClearContents
Dim stk_valid As Range
Set stk_valid = Sheet17.Range("B40")
stk_valid.Validation.Delete
Dim acq_valid As Range
Set acq_valid = Sheet17.Range("b41")
stk_valid.Validation.Delete
On Error GoTo MyErrorHandler:
Dim acqstk As String
acqstk = Sheet17.Range("b40")
AcqNum = Application.WorksheetFunction.VLookup(acqstk, Sheet3.Range("a2:ad4000"), 14, False)
Sheet17.Range("b41").Value = AcqNum
acqscr = Application.WorksheetFunction.VLookup(acqstk, Sheet3.Range("a2:ad4000"), 27, False)
Sheet17.Range("b42").Value = acqscr
acqdate = Application.WorksheetFunction.VLookup(acqstk, Sheet3.Range("a2:ad4000"), 3, False)
Sheet17.Range("b43").Value = acqdate
acqlicence = Application.WorksheetFunction.VLookup(acqstk, Sheet3.Range("a2:ad4000"), 13, False)
Sheet17.Range("b46").Value = acqlicence
acqname = Application.WorksheetFunction.VLookup(acqstk, Sheet3.Range("a2:ad4000"), 10, False)
Sheet17.Range("b47").Value = acqname
acqadress = Application.WorksheetFunction.VLookup(acqstk, Sheet3.Range("a2:ad4000"), 11, False)
Sheet17.Range("b49").Value = acqadress
acqrego = Application.WorksheetFunction.VLookup(acqstk, Sheet3.Range("a2:ad4000"), 4, False)
Sheet17.Range("b50").Value = acqrego
acqmake = Application.WorksheetFunction.VLookup(acqstk, Sheet3.Range("a2:ad4000"), 6, False)
Sheet17.Range("b51").Value = acqmake
acqmodel = Application.WorksheetFunction.VLookup(acqstk, Sheet3.Range("a2:ad4000"), 7, False)
Sheet17.Range("b52").Value = acqmodel
acqserial = Application.WorksheetFunction.VLookup(acqstk, Sheet3.Range("a2:ad4000"), 5, False)
Sheet17.Range("b53").Value = acqserial
acqcalibre = Application.WorksheetFunction.VLookup(acqstk, Sheet3.Range("a2:ad4000"), 8, False)
Sheet17.Range("c54").Value = acqcalibre
acqftype = Application.WorksheetFunction.VLookup(acqstk, Sheet3.Range("a2:ad4000"), 22, False)
Sheet17.Range("b55").Value = acqftype
acqloadact = Application.WorksheetFunction.VLookup(acqstk, Sheet3.Range("a2:ad4000"), 23, False)
Sheet17.Range("b56").Value = acqloadact
acqatype = Application.WorksheetFunction.VLookup(acqstk, Sheet3.Range("a2:ad4000"), 24, False)
Sheet17.Range("b57").Value = acqatype
acqptype = Application.WorksheetFunction.VLookup(acqstk, Sheet3.Range("a2:ad4000"), 25, False)
Sheet17.Range("b58").Value = acqptype
acqmagcap = Application.WorksheetFunction.VLookup(acqstk, Sheet3.Range("a2:ad4000"), 26, False)
Sheet17.Range("b59").Value = acqmagcap
acqpisbbllen = Application.WorksheetFunction.VLookup(acqstk, Sheet3.Range("a2:ad4000"), 9, False)
Sheet17.Range("b60").Value = acqpisbbllen
acqprimbblserial = Application.WorksheetFunction.VLookup(acqstk, Sheet3.Range("a2:ad4000"), 28, False)
Sheet17.Range("b61").Value = acqprimbblserial
acqefims = Application.WorksheetFunction.VLookup(acqstk, Sheet3.Range("a2:ad4000"), 30, False)
Sheet17.Range("b62").Value = acqefims
UPDATPAB31.Show
Dim serial_gen As Range
serial_gen = "b53"
serial_gen.NumberFormat = "@"
Exit Sub
MyErrorHandler:
If Err.Number = 1004 Then
Exit Sub
End If
Display More
Any suggestions as to why the second lot of code doesn't play?
Regards