I have this vlookup in my code and I get the following error: unable to get the vlookup property of the worksheet function class. Can anyone help me on this.
Sub update_headers()
'====================================================================
' UPDATE HEADER SHEETS
'
'Description: Automatically updates header sheets with header you request
'
'Macro Created on 3/16/2006
'
'Written by Wendy Smith
'=========================================================================
Dim cellstart As Integer 'starting point of informaiton (row)
Dim commentstart As Integer 'starting point for comments (row)
Dim p As Integer
Dim c As Integer 'for comments
Dim h As Integer 'for comments
Dim x As Integer
Dim r As String 'counting variable for comments
Dim n As String 'counting variable
Dim TestRange As String 'Test String
Dim TestRange2 As String 'Test String
Dim TestRange3 As String 'Test String
Dim TestRange4 As String
Dim TestRange5 As String
Dim TestRange6 As String 'Test String for notes
Dim TestRange7 As String 'Test String for notes
Dim TestRange8 As String 'Test String for notes
Dim TestRange9 As String 'test string for notes
Dim m As String
Dim y As String 'for comments
Dim sh As String 'source sheet
Dim destsh As String 'dest sheet
Dim notes As String 'source sheet for comments
Dim reportlocation As String
Dim sFirstAddress As String
Dim header As String 'header you want to run Holds header
Dim output(1 To 8) As String
Dim myrange As Range
Dim rsearch As Range
cellstart = 3 'Starting point of source sheet
commentsstart = 4 'starting point for comments increase this number only if you need more comment space
p = 0
c = 0
header = InputBox("Which header do you want to run?", "header") 'input the requested header
TestRange = header
sh = "Daily" 'Work sheet where the header information is kept
destsh = header ' desination sheet for header
notes = "Notes" 'work sheet for notes
'Clear out old Data and unhide rows
sheets(destsh).Range("A4:A100").Select
Selection.ClearContents
Selection.EntireRow.Hidden = False
n = cellstart
r = commentsstart
TestRange2 = "B" + n 'column where to match header request
TestRange3 = "A" + n 'part number
TestRange4 = "AF" + n 'over 60 days
TestRange5 = "AE" + n 'furture 6
For x = 1 To 1000 'increase this number only if daily sheet has more than 1000 parts
If UCase(Trim(TestRange)) = UCase(Trim(sheets(sh).Range(TestRange2))) And UCase(Trim(sheets(sh).Range(TestRange4) < 61)) Then
p = p + 1
m = p + 3 'Tells where to start importing information on dest sheet
reportlocation = "A" + m 'starting point of output file
sheets(sh).Range(TestRange3).Copy sheets(destsh).Range(reportlocation)
reportlocation = "CA" + m
sheets(sh).Range(TestRange3).Copy sheets(destsh).Range(reportlocation)
n = n + 1
TestRange2 = "B" + n
TestRange3 = "A" + n
TestRange4 = "AF" + n
TestRange5 = "AE" + n
ElseIf UCase(Trim(TestRange)) = UCase(Trim(sheets(sh).Range(TestRange2))) And UCase(Trim(sheets(sh).Range(TestRange4) > 60)) And UCase(Trim(sheets(sh).Range(TestRange5) > 0)) Then
p = p + 1
m = p + 3 'Tells where to start importing information on dest sheet
reportlocation = "A" + m 'starting point of output file
sheets(sh).Range(TestRange3).Copy sheets(destsh).Range(reportlocation)
reportlocation = "CA" + m
sheets(sh).Range(TestRange3).Copy sheets(destsh).Range(reportlocation)
n = n + 1
TestRange2 = "B" + n
TestRange3 = "A" + n
TestRange4 = "AF" + n
TestRange5 = "AE" + n
Else
n = n + 1
TestRange2 = "B" + n
TestRange3 = "A" + n
TestRange4 = "AF" + n
TestRange5 = "AE" + n
End If
Next
'Hide empty rows
m = m + 1
reportlocation = "A" + m
Do While sheets(destsh).Range(reportlocation).Value = ""
sheets(destsh).Range(reportlocation).EntireRow.Hidden = True
m = m + 1
reportlocation = "A" + m
Loop
'Move Comments
sheets(destsh).Range("A104:B204").Select
Selection.ClearContents
output(7) = "CA" + r 'dest sheet part numbers
output(8) = sheets(destsh).Range(output(7)).Text
TestRange9 = output(8)
output(1) = "A" + r 'part numbers
output(2) = sheets(notes).Range(output(1)).Value
TestRange8 = output(2)
output(5) = "C" + r 'comments
output(6) = sheets(notes).Range(output(5)).Text
TestRange7 = output(6)
Do
Set myrange = sheets(destsh).Range(output(7))
Set rsearch = sheets(notes).Range(output(1))
'Set reportlocation2 = sheets(notes).Range(output(5))
Set rsearch = myrange.Find(what:=sheets(destsh).Range(output(7)), after:=myrange.Cells(myrange.Cells.Count), lookat:=xlWhole)
If Not myrange Is Nothing Then
sFirstAddress = rsearch.Address
If rsearch = myrange And reportlocation2 <> "" Then
c = c + 1
y = c + 103 'Tells where to start importing comments
reportlocation = "A" + y 'Starting row of part numbers for comments
rsearch.Copy sheets(destsh).Range(reportlocation)
reportlocation = "B" + y 'comments
-----------> rsearch = Application.WorksheetFunction.vlookup(A104, Worksheets("Notes").Range("A4:C400"), 3)
'reportlocation2.Copy sheets(destsh).Range(reportlocation)
'Set myrange = rsearch.FindNext(myrange)
Set rsearch = myrange.FindNext(rsearch)
End If
End If
r = r + 1
output(7) = "CA" + r
'output(5) = "C" + r
Loop Until myrange = ""
End Sub
Sub update_headers()
'====================================================================
' UPDATE HEADER SHEETS
'
'Description: Automatically updates header sheets with header you request
'
'Macro Created on 3/16/2006
'
'Written by Wendy Smith
'=========================================================================
Dim cellstart As Integer 'starting point of informaiton (row)
Dim commentstart As Integer 'starting point for comments (row)
Dim p As Integer
Dim c As Integer 'for comments
Dim h As Integer 'for comments
Dim x As Integer
Dim r As String 'counting variable for comments
Dim n As String 'counting variable
Dim TestRange As String 'Test String
Dim TestRange2 As String 'Test String
Dim TestRange3 As String 'Test String
Dim TestRange4 As String
Dim TestRange5 As String
Dim TestRange6 As String 'Test String for notes
Dim TestRange7 As String 'Test String for notes
Dim TestRange8 As String 'Test String for notes
Dim TestRange9 As String 'test string for notes
Dim m As String
Dim y As String 'for comments
Dim sh As String 'source sheet
Dim destsh As String 'dest sheet
Dim notes As String 'source sheet for comments
Dim reportlocation As String
Dim sFirstAddress As String
Dim header As String 'header you want to run Holds header
Dim output(1 To 8) As String
Dim myrange As Range
Dim rsearch As Range
cellstart = 3 'Starting point of source sheet
commentsstart = 4 'starting point for comments increase this number only if you need more comment space
p = 0
c = 0
header = InputBox("Which header do you want to run?", "header") 'input the requested header
TestRange = header
sh = "Daily" 'Work sheet where the header information is kept
destsh = header ' desination sheet for header
notes = "Notes" 'work sheet for notes
'Clear out old Data and unhide rows
sheets(destsh).Range("A4:A100").Select
Selection.ClearContents
Selection.EntireRow.Hidden = False
n = cellstart
r = commentsstart
TestRange2 = "B" + n 'column where to match header request
TestRange3 = "A" + n 'part number
TestRange4 = "AF" + n 'over 60 days
TestRange5 = "AE" + n 'furture 6
For x = 1 To 1000 'increase this number only if daily sheet has more than 1000 parts
If UCase(Trim(TestRange)) = UCase(Trim(sheets(sh).Range(TestRange2))) And UCase(Trim(sheets(sh).Range(TestRange4) < 61)) Then
p = p + 1
m = p + 3 'Tells where to start importing information on dest sheet
reportlocation = "A" + m 'starting point of output file
sheets(sh).Range(TestRange3).Copy sheets(destsh).Range(reportlocation)
reportlocation = "CA" + m
sheets(sh).Range(TestRange3).Copy sheets(destsh).Range(reportlocation)
n = n + 1
TestRange2 = "B" + n
TestRange3 = "A" + n
TestRange4 = "AF" + n
TestRange5 = "AE" + n
ElseIf UCase(Trim(TestRange)) = UCase(Trim(sheets(sh).Range(TestRange2))) And UCase(Trim(sheets(sh).Range(TestRange4) > 60)) And UCase(Trim(sheets(sh).Range(TestRange5) > 0)) Then
p = p + 1
m = p + 3 'Tells where to start importing information on dest sheet
reportlocation = "A" + m 'starting point of output file
sheets(sh).Range(TestRange3).Copy sheets(destsh).Range(reportlocation)
reportlocation = "CA" + m
sheets(sh).Range(TestRange3).Copy sheets(destsh).Range(reportlocation)
n = n + 1
TestRange2 = "B" + n
TestRange3 = "A" + n
TestRange4 = "AF" + n
TestRange5 = "AE" + n
Else
n = n + 1
TestRange2 = "B" + n
TestRange3 = "A" + n
TestRange4 = "AF" + n
TestRange5 = "AE" + n
End If
Next
'Hide empty rows
m = m + 1
reportlocation = "A" + m
Do While sheets(destsh).Range(reportlocation).Value = ""
sheets(destsh).Range(reportlocation).EntireRow.Hidden = True
m = m + 1
reportlocation = "A" + m
Loop
'Move Comments
sheets(destsh).Range("A104:B204").Select
Selection.ClearContents
output(7) = "CA" + r 'dest sheet part numbers
output(8) = sheets(destsh).Range(output(7)).Text
TestRange9 = output(8)
output(1) = "A" + r 'part numbers
output(2) = sheets(notes).Range(output(1)).Value
TestRange8 = output(2)
output(5) = "C" + r 'comments
output(6) = sheets(notes).Range(output(5)).Text
TestRange7 = output(6)
Do
Set myrange = sheets(destsh).Range(output(7))
Set rsearch = sheets(notes).Range(output(1))
'Set reportlocation2 = sheets(notes).Range(output(5))
Set rsearch = myrange.Find(what:=sheets(destsh).Range(output(7)), after:=myrange.Cells(myrange.Cells.Count), lookat:=xlWhole)
If Not myrange Is Nothing Then
sFirstAddress = rsearch.Address
If rsearch = myrange And reportlocation2 <> "" Then
c = c + 1
y = c + 103 'Tells where to start importing comments
reportlocation = "A" + y 'Starting row of part numbers for comments
rsearch.Copy sheets(destsh).Range(reportlocation)
reportlocation = "B" + y 'comments
-----------> rsearch = Application.WorksheetFunction.vlookup(A104, Worksheets("Notes").Range("A4:C400"), 3)
'reportlocation2.Copy sheets(destsh).Range(reportlocation)
'Set myrange = rsearch.FindNext(myrange)
Set rsearch = myrange.FindNext(rsearch)
End If
End If
r = r + 1
output(7) = "CA" + r
'output(5) = "C" + r
Loop Until myrange = ""
End Sub