LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Using VLookup in VBA code with variable range

In the code you posted, you declared PHDResult as a variant with a line like:

Dim PHDResult

If you're going to use application.vlookup() (not
application.worksheetfunction.vlookup()), then you'll want to make sure
PHDResult is a variant (not string, not long...)

Then you can test the results of the =vlookup() with:

phdresult = application.vlookup(...)
if iserror(phdresult) then
msgbox "it wasn't found" 'same as #n/a error
else
msgbox phdresult
end if

===
Can you get the formula to work if you put it in a cell in a worksheet?

If you cannot, you may want to look at Debra Dalgleish's site:
http://contextures.com/xlFunctions02.html#Trouble

Maybe your values aren't what you think they are.




Tommy wrote:

I have changed my code accordingly but I still have a type mismatch
(Runtime Error '13'), which comes on this line:

PHDResult = Application.VLookup(CellValuePHD, Range(Cells(4, 1),
Cells(4, 15).End(xlDown)), 0)

Note that i declared PHDResult as a string.


--

Dave Peterson
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
VLOOKUP variable range cell reference Ohp Excel Worksheet Functions 2 July 3rd 07 02:52 PM
Vlookup using variable path name for range value Jeff Lowenstein Excel Worksheet Functions 1 February 9th 06 01:13 AM
VLOOKUP using a range variable Henry Hayden Excel Programming 2 November 15th 05 10:55 PM
Code to copy formula to variable range Snowsride Excel Programming 4 November 3rd 05 09:41 PM
VBA Code to name a variable range John Excel Programming 6 July 14th 05 05:15 PM


All times are GMT +1. The time now is 03:06 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"