Hi All,
Wondering if I can get some expert advice from someone on my issue.
I've written some code for a script for slicing and dicing data which works perfectly in Excel 2010, but 2003 doesn't like it unfortunately.
Probably an easy one for an expert set of eyes, but my lack of real experience in scripting is hurting me here is I do not understand why what I have written fails in excel 2003.
The idea behind my code is that I'm searching a data set for parts in a given location; the output tells me if I have a part in a particular location based on the state and the part number.
Here is my code (or part of) that I get the error on:
.Range("H2:H" & pRow).Formula = "=VLOOKUP(A2,All_Parts!$" & FirstRow & FirstCol & ":$" & LastRow & LastCol & ",2,FALSE)"
The error I receive is a 1004 object defined error
Here is the rest
Dim UsedRng As Range
Dim FirstRow As Long, LastRow As Long, FirstCol As Long, LastCol As Long, pRow As Long
Set UsedRng = ActiveWorkbook.Sheets("All_Parts").UsedRange
FirstRow = UsedRng(1).Row
FirstCol = UsedRng(1).Column
LastRow = UsedRng(UsedRng.Cells.Count).Row
LastCol = UsedRng(UsedRng.Cells.Count).Column
Application.StatusBar = "Validating, locations & confirming part numbers"
With Sheets("Successful")
'set the range to copy - this time, I'm using the postcode row
pRow = .Range("F" & Rows.Count).End(xlUp).Row
.Range("F1:F" & pRow).AutoFilter Field:=1, Criteria1:="<>"
'check the postcode
.Range("G2:G" & pRow).Formula = "=IF(ISERROR(VLOOKUP(F2,Postcodes!$A$2:$A$855,1,FALSE)),""REMOTE"",""METRO"")"
.Range("G2").AutoFilter
'check the FRU
'.Range("H2:H" & pRow).Formula = "=VLOOKUP(A2,All_Parts!$A$1:$B$1528,2,FALSE)" ' <- This works in 2003
.Range("H2:H" & pRow).Formula = "=VLOOKUP(A2,All_Parts!$" & FirstRow & FirstCol & ":$" & LastRow & LastCol & ",2,FALSE)" ' <- This doesnt in 2003
.Range("H2").AutoFilter
The reason for using variables in the VLOOKUP is because data is regularly added to the "All_Parts" tab so I figured doing it this way would ensure that the VLOOKUP searches all new data.
I've tried removing the $ signs from the line and reversing the "FirstRow" and "FirstCol"
I can confirm that this line ".Range("H2:H" & pRow).Formula = "=VLOOKUP(A2,All_Parts!$A$1:$B$1528,2,FALSE)"" works when I test with it so I know its something to do with the variables or how I've written it.
I've also considered my data sets, but they are all under 65535 lines so that shouldnt be an issue
Any feedback would be appreciated and I thank you in advance !!
All the best
Steve
Bookmarks