Page 2 of 2 FirstFirst 12
Results 11 to 13 of 13

Thread: Error when running VLookup

  1. #11
    Member p45cal's Avatar
    Join Date
    Oct 2013
    Posts
    94
    Rep Power
    12
    Quote Originally Posted by mcbrocks View Post
    all except for the first cells property: Cells(10, Column). It's showing the correct column, but the value of this cell, is from my active sheet and not the referenced sheet, meaning: It shows: Worksheets(DataPVC2) <--in the pop up box. BUT the cell displays the value from Worksheets(DataThermo2) <-- or whatever worksheet is active.
    I think you've nailed it - and I should have seen this - the range is not properly qualified; the Cells(…) parts need to be qualified:
    Code:
    With Worksheets(WorksheetName)
      VoltageDrop = WorksheetFunction.VLookup(Val(LoadCurrentText.Text), .Range(.Cells(10, Column), .Cells(26, VoltageDropColumn)), ReturnColumn)
    End With
    paying especial attention to the dots in the code. The With… End With consruct could probably span more than one line.
    Last edited by p45cal; 02-27-2014 at 04:11 PM.

  2. #12
    Junior Member
    Join Date
    Feb 2014
    Posts
    8
    Rep Power
    0
    p45cal, it works!!! I didn't know it had to be so specific. But however, I have some cells within the range that contain a 0 value. This throws off the desired result. Is there any line that can be put in to rectify the error? I tried this:
    Code:
        If Worksheets(WorksheetName).Range(Worksheets(WorksheetName).Cells(10, Column), Worksheets(WorksheetName).Cells(26, Column)).Value = 0 Then
            Ans = MsgBox("This method does not exist for " & WorksheetName & ".", vbRetryCancel + vbExclamation)
            If Ans = vbRetry Then CableSizingSelection.UndoAction
            If Ans = vbCancel Then Unload CableSizingSelection
        End If
    But the first If line is giving trouble.

    Is there any other way to avoid the error? There are some columns where only the last few rows contain 0s and if the lookup value can be found within the top few lines, the program would have to work correctly. I realized the retry cancel actually searches for 0 values whether it affects the result or not. Maybe I could shorten the lookup range. Like say have the range from row 10 to the last non-0 cell?
    Last edited by mcbrocks; 02-28-2014 at 08:02 AM.

  3. #13
    Junior Member
    Join Date
    Feb 2014
    Posts
    8
    Rep Power
    0
    Here's the updated copy of the worksheet when I switch to using index match instead of vlookup.
    Attachment 1510

    I've posted this question over here as well Error with index match function - Page 2
    Attached Files Attached Files
    Last edited by mcbrocks; 03-12-2014 at 06:14 AM.

Similar Threads

  1. Replies: 1
    Last Post: 10-30-2013, 10:27 PM
  2. Macro stops running if date is not in past...
    By Carlos Arruda in forum Excel Help
    Replies: 4
    Last Post: 03-10-2013, 04:33 PM
  3. Saving and Running Macro For Multiple Files / Users
    By Charles_ in forum Excel Help
    Replies: 1
    Last Post: 01-07-2013, 09:10 AM
  4. Workbook Event running VBA question
    By jamilm in forum Excel Help
    Replies: 4
    Last Post: 12-29-2012, 12:12 AM
  5. Running a VBA in all excel files
    By msiyab in forum Excel Help
    Replies: 3
    Last Post: 12-26-2012, 01:35 PM

Posting Permissions

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