+ Reply to Thread
Results 1 to 13 of 13

“Unable to get the VLookup property of the WorksheetFunction Class” error

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-23-2015
    Location
    Toronto, Ontario
    MS-Off Ver
    Excel 2010
    Posts
    187

    “Unable to get the VLookup property of the WorksheetFunction Class” error

    Hi all, I am trying to set the values in column B in my Workbook "Copy of Dash Board Shell" (shown in the image below) equal to the value derived from my HLOOKUP function from my data workbook shown as second image below
    Copy of Dash Board Shell
    Capture.PNG

    Data File
    capture 1.PNG

    so esentially the code will find a match in the data file and copy its MIS number and paste it in the desired location on the Dash Board file, heres my code, I keep getting an error because I dont know the syntax, can someone help?

    Sub RetrieveData()
    
        Dim wbDash              As Workbook 'workbook where the data is to be pasted
        Dim wbData              As Workbook 'workbook from where the data is to copied
          
        
        'set to the current active workbook to Dashboard
        Set wbDash = ActiveWorkbook
        'Setting data sheet
        Set wbData = Workbooks.Open("C:\Users\673157897\Documents\Pro Fees Dash Board\Copy of Data.xls")
      
        Workbooks("Copy of Dash Board Shell").Worksheets("Data").Activate
           
    With Sheets("Data")
    
        ' Selects the first cell to check
        Range("A3").Select
        Dim x As Variant
        x = wbData.Worksheets("Sheet1").Range("A2:B7")
        Workbooks("Copy of Dash Board Shell").Worksheets("Data").Range("A3").Select
       
        ' Loops through all rows until an empty row is found
        Do Until IsEmpty(ActiveCell)
    
            Range(ActiveCell.Offset(0, 1) & ActiveCell.Row).Value = Application.WorksheetFunction.VLookup((ActiveCell.Column & ActiveCell.Row), x, 2, 0)
            ActiveCell.Offset(1, 0).Select
    
    ' error is the syntax of the VLOOKUP
    
        Loop
    End With
    
    Call wbData.Close(False)
    End Sub

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: “Unable to get the VLookup property of the WorksheetFunction Class” error

    Maybe:

    ActiveCell.Offset(0, 1).Value = _ 
    WorksheetFunction.VLookup(ActiveCell, x, 2, 0)
            ActiveCell.Offset(1, 0).Select
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Forum Contributor
    Join Date
    09-23-2015
    Location
    Toronto, Ontario
    MS-Off Ver
    Excel 2010
    Posts
    187

    Re: “Unable to get the VLookup property of the WorksheetFunction Class” error

    I get another syntax error with that.... Capture.PNG

  4. #4
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: “Unable to get the VLookup property of the WorksheetFunction Class” error

    Quote Originally Posted by lougs7 View Post
    I get another syntax error with that.... Attachment 423943
    If you feel the need to post images please do not use .PNG format, they are not visible to most users.

    edit:- I was able to view the image by opening the attachment, you got an error because you didn't copy xladept's code correctly.

    Delete "Range(" from the start of the erroneous line then it should compile, though no guarantee it will execute without error.
    Last edited by jason.b75; 10-09-2015 at 04:55 PM.

  5. #5
    Forum Contributor
    Join Date
    09-23-2015
    Location
    Toronto, Ontario
    MS-Off Ver
    Excel 2010
    Posts
    187

    Re: “Unable to get the VLookup property of the WorksheetFunction Class” error

    sorry wont post .PNG anymore. What file format is best?

  6. #6
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: “Unable to get the VLookup property of the WorksheetFunction Class” error

    Jpeg is probably the safest if you do need to post an image.

    I have edited my previous post to show why you had the error with xladept's suggestion.

    Which line was the error caused by in my code? It was a quick untested hash so it could have a couple of typos in it.

  7. #7
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: “Unable to get the VLookup property of the WorksheetFunction Class” error

    You don't need to select or activate ranges or sheets in your code, the only purpose those functions serve is to make your code slower.
    Personally I would use Range.Find over calling Vlookup, something like.

    Option Explicit
    Sub RetrieveData()
    
    Dim wbDash As Workbook 'workbook where the data is to be pasted
    Dim wbData As Workbook 'workbook from where the data is to copied
    Dim c As Range, rng As Range, rfound As Range
        'set to the current active workbook to Dashboard
    Set wbDash = ActiveWorkbook
        'Setting data sheet
    Set wbData = Workbooks.Open("C:\Users\673157897\Documents\Pro Fees Dash Board\Copy of Data.xls")
    Set rng = wbData.Worksheets("Sheet1").Range("A2:A7")
    With Workbooks("Copy of Dash Board Shell").Sheets("Data")
    
        ' Selects the first cell to check
        For Each c In .Range("A3", .Cells(Rows.Count, "A").End(xlUp).Row)
            Set rfound = rng.Find(what:=c, after:=rng(1), LookIn:=xlValues, lookat:=xlWhole)
            If Not rfound Is Nothing Then
                c.Offset(0, 1) = rfound.Offset(0, 1)
            Else
                c.Offset(0, 1) = "N/A"
            End If
        Next
    End With
        wbData.Close (False)
    End Sub

  8. #8
    Forum Contributor
    Join Date
    09-23-2015
    Location
    Toronto, Ontario
    MS-Off Ver
    Excel 2010
    Posts
    187

    Re: “Unable to get the VLookup property of the WorksheetFunction Class” error

    Quote Originally Posted by jason.b75 View Post
    You don't need to select or activate ranges or sheets in your code, the only purpose those functions serve is to make your code slower.
    Personally I would use Range.Find over calling Vlookup, something like.

    Option Explicit
    Sub RetrieveData()
    
    Dim wbDash As Workbook 'workbook where the data is to be pasted
    Dim wbData As Workbook 'workbook from where the data is to copied
    Dim c As Range, rng As Range, rfound As Range
        'set to the current active workbook to Dashboard
    Set wbDash = ActiveWorkbook
        'Setting data sheet
    Set wbData = Workbooks.Open("C:\Users\673157897\Documents\Pro Fees Dash Board\Copy of Data.xls")
    Set rng = wbData.Worksheets("Sheet1").Range("A2:A7")
    With Workbooks("Copy of Dash Board Shell").Sheets("Data")
    
        ' Selects the first cell to check
        For Each c In .Range("A3", .Cells(Rows.Count, "A").End(xlUp).Row)
            Set rfound = rng.Find(what:=c, after:=rng(1), LookIn:=xlValues, lookat:=xlWhole)
            If Not rfound Is Nothing Then
                c.Offset(0, 1) = rfound.Offset(0, 1)
            Else
                c.Offset(0, 1) = "N/A"
            End If
        Next
    End With
        wbData.Close (False)
    End Sub


    Hey Jason, Im open to anything if you think find is better I may just use that.

    I got an error though, it says "Application-defined or Object-defined error" when I run the code

    Attachment 423947

    Do you know how to get around this?

  9. #9
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: “Unable to get the VLookup property of the WorksheetFunction Class” error

    Hopefully xladept can answer that one, error handling is one of my reasons for using Find instead of Vlookup.

    Using Find, this part traps any potential errors
            If Not rfound Is Nothing Then
                c.Offset(0, 1) = rfound.Offset(0, 1)
            Else
                c.Offset(0, 1) = "N/A"
            End If
    Basically no match returns an empty variable (rFound Is Nothing) so we can tell the code what to do if the match is nothing or if it is something, there is no error involved here.
    With Vlookup, no match automatically returns an error, so you have to trap in, either with more worksheet functions, or with vba On Error, both of which can get pretty messy.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Unable to get the Vlookup Property of the WorkSheetFunction Class
    By jayeshsondhi in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-22-2015, 03:57 AM
  2. Run - time error '1004': Unable to get the Sum property of WorksheetFunction class
    By dylanrose in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-06-2013, 10:25 AM
  3. [SOLVED] Unable to Get the Vlookup property of the WorksheetFunction class
    By DrowingInVBA in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-19-2013, 02:02 PM
  4. Run-time Error 1004: Unable to get the VLookup property of the WorksheetFunction class
    By sridhar_neel in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-10-2012, 04:21 AM
  5. Unable to get the VLookup property of the WorksheetFunction class
    By JesseBurton in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 12-09-2009, 10:29 AM
  6. Replies: 2
    Last Post: 12-13-2007, 09:59 AM
  7. Unable to get the Vlookup property of the WorksheetFunction class
    By DoctorG in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-17-2006, 02:55 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1