I am trying to use the vlookup function on a range of cells, that looks up values in other sheets. However I ckeep getting a runtime error that says "application defined or object defined error."
ActiveSheet.Range("$A$1", Selection.End(xlDown)).RemoveDuplicates Columns:=1, _
Header:=xlYes
'In Summary Tab
Range("A1").CurrentRegion.Select
nRows = Selection.Rows.Count
' Places column headers in "Summary" tab
For iCounter = 2 To Sheets.Count
Sheets(iCounter).Select
Range("A1").CurrentRegion.Select
nCols = Selection.Columns.Count
For iColumn = 2 To nCols
Sheets(iCounter).Select
If (WorksheetFunction.IsNumber(Cells(2, iColumn)) = "TRUE") Then
Cells(1, iColumn).Select
Selection.Copy
Sheets("Summary").Select
ActiveCell.Offset(0, 1).PasteSpecial
Application.CutCopyMode = False
ActiveCell.Offset(1, 0).Select
ActiveCell.Resize(nRows - 1, 1).Select
Selection.Formula = "=vlookup(B2," & _
Range(sheets(icounter).selection).Address","& icolumn",false)"
End If
Next
Next
I also tried editing the vlookup formula to this, (with everything else the same):
Selection = Application.WorksheetFunction.VLookup( _
"B2", Sheets(iCounter).CurrentRegion.Select, iColumn, False)
But this gives error 438 "object doesn't support this property or method"
Even tried editing the vlookup to this but got the 1004 error again:
Selection = Application.WorksheetFunction.VLookup("B2",Sheets(iCounter).Range(Cells(1, 1), Cells(nCols, nRows)), iColumn, False)