I am having trouble with VLookUp and it is driving me crazy. I have tried the two macros below with different results. I have verified the source sheet name as JobsAll. I have verified the case of the letters and have even tried JOBSALL in both code and the sheet name. One macro shows G2 and H2 as the receiving cells and the other shows D2 and E2. I did this so I could test both and see the results. I am trying to copy # values over to the receiving sheet. I have verified that both the source and receiving sheets are in numerical order with the source and requesting columns of info of both sheets in col A. They are numbers in both. I have verified headers in row 1 of both sheets. I have verified that the last value in column F of the second macro is a number. There are 2479 rows of data in the JobsAll sheet and the current receiving sheet has only 35 rows of data. I have tried .Value and .Formula. I have also tried with no luck the following in both macros (with adjustments for the column #).
'this one gives #NAME? in the cells
---------------------------------
'this one gives #N/A in cells.
The reason I feel that there is a problem with the sheet and not the code is that the following macro also does not work when trying to pull over a non-numeric description of the info being asked for BUT this macro DOES work in a different WB. The macro has been copied and pasted exactly as written from the different workbook where it works as it is written, but it will not work in the WB that I am trying to get it to work in now.
I have read many posts and checked my notes on VLookUp but this one really has me stumped. No doubt it will be a "duh" moment when the answer is revealed, but right now I am lost. Thanks for any help.
Code:
Dim LastRow As Range
Set LastRow = Range("A65536").End(xlUp)
.Formula = "=VLOOKUP(A1, JobsAll!$A$1:$F$" & LastRow & ", 3, FALSE)"
'this one gives #NAME? in the cells
Code:
Sub VLookUpCopiedPieceRateAndStandard()
Application.StatusBar = "Accessing Piece Rates and Standards"
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim LastRow As Long
LastRow = Range("A65536").End(xlUp).Row
'G2 is the piece rate on timesheet receiving the info
With Range("G2") 'must be a comma before and after "2" in following line
.Formula = "=VLOOKUP(A2, JobsAll, 2, FALSE)"
.AutoFill Destination:=Range(Cells(.Row, .Column), Cells(Cells(2, 1).End(xlDown).Row, .Column)), Type:=xlFillDefault
End With
'H2 is the standard on the sheet receiving the info
With Range("H2")
.Formula = "=VLOOKUP(A2, JobsAll, 3, FALSE)" 'sheet is actually JobsAll. But this works.
.AutoFill Destination:=Range(Cells(.Row, .Column), Cells(Cells(2, 1).End(xlDown).Row, .Column)), Type:=xlFillDefault
End With
End Sub
---------------------------------
'this one gives #N/A in cells.
Code:
Sub VLookUpCopiedPieceRateAndStandard999()
Application.StatusBar = "Accessing Piece Rates and Standards"
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim LastRow As Long
LastRow = Range("A65536").End(xlUp).Row ' or
'tried .Value also. Same result
With Range("D1") 'must be a comma before and after "2" in following line
.Formula = "=VLOOKUP(A1, JobsAll!$A$1:$F$" & LastRow & ", 2, FALSE)"
.AutoFill Destination:=Range(Cells(.Row, .Column), Cells(Cells(2, 1).End(xlDown).Row, .Column)), Type:=xlFillDefault
End With
'tried .Value also. Same result
'Range("E1").Select ''E is the standard
With Range("E1")
.Formula = "=VLOOKUP(A1, JobsAll!$A$1:$F$" & LastRow & ", 3, FALSE)" 'sheet is actually JobsAll. But this works.
.AutoFill Destination:=Range(Cells(.Row, .Column), Cells(Cells(2, 1).End(xlDown).Row, .Column)), Type:=xlFillDefault
End With
End Sub
The reason I feel that there is a problem with the sheet and not the code is that the following macro also does not work when trying to pull over a non-numeric description of the info being asked for BUT this macro DOES work in a different WB. The macro has been copied and pasted exactly as written from the different workbook where it works as it is written, but it will not work in the WB that I am trying to get it to work in now.
Code:
Sub VLookUpCopiedStepDescription()
Application.StatusBar = "Accessing Step Description "
Application.ScreenUpdating = False
Dim LastRow As Long
LastRow = Range("A65536").End(xlUp).Row ' or
'Range("B1").Select 'D is the piece rate on timesheet
With Range("B2") 'must be a comma before and after "2" in following line
.Value = "=VLOOKUP(A1, JobsAll, 5, FALSE)"
.AutoFill Destination:=Range(Cells(.Row, .Column), Cells(Cells(2, 1).End(xlDown).Row, .Column)), Type:=xlFillDefault
End With
Application.ScreenUpdating = True
End Sub
I have read many posts and checked my notes on VLookUp but this one really has me stumped. No doubt it will be a "duh" moment when the answer is revealed, but right now I am lost. Thanks for any help.