Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default Vlookup result in a message box

I have code that returns a variable "l" to cell H17. (lowercase L)

Range("H17").Value = l

That value is used to return a vlookup value to a cell with the following formula.

=IF(ISERROR(VLOOKUP(H17,L2:Q75,J2,0)),"Game ?",VLOOKUP(H17,L2:Q75,J2,0))

I want that vlookup returned value to show in a message box.
This does not compile along with a few other tries.

MsgBox application.WorksheetFunction =IF(ISERROR(VLOOKUP(H17,L2:Q75,J2,0)),""Game ?"",VLOOKUP(H17,L2:Q75,J2,0))

Thanks.
Howard
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Vlookup result in a message box

I have code that returns a variable "l" to cell H17. (lowercase L)

Range("H17").Value = l

That value is used to return a vlookup value to a cell with the
following formula.

=IF(ISERROR(VLOOKUP(H17,L2:Q75,J2,0)),"Game
?",VLOOKUP(H17,L2:Q75,J2,0))

I want that vlookup returned value to show in a message box.
This does not compile along with a few other tries.

MsgBox application.WorksheetFunction
=IF(ISERROR(VLOOKUP(H17,L2:Q75,J2,0)),""Game
?"",VLOOKUP(H17,L2:Q75,J2,0))

Thanks.
Howard


Pass the value of the cell containing the formula to MsgBox...

MsgBox Range("???").Value

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default Vlookup result in a message box


Pass the value of the cell containing the formula to MsgBox...



MsgBox Range("???").Value



--

Garry


Okay, that was just a test to see if you are paying attention...<g

Thanks,
Howard
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Vlookup result in a message box


Pass the value of the cell containing the formula to MsgBox...



MsgBox Range("???").Value



--

Garry


Okay, that was just a test to see if you are paying attention...<g

Thanks,
Howard


Ha, ha, ha, ha, ha...

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Vlookup result in a message box

Hi Howard,

Am Mon, 8 Sep 2014 13:45:54 -0700 (PDT) schrieb L. Howard:

=IF(ISERROR(VLOOKUP(H17,L2:Q75,J2,0)),"Game ?",VLOOKUP(H17,L2:Q75,J2,0))


for Excel version 2007 or newer you can use:
=IFERROR(VLOOKUP(H17,L2:Q75,J2,0),"Game?")



Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default Vlookup result in a message box


for Excel version 2007 or newer you can use:

=IFERROR(VLOOKUP(H17,L2:Q75,J2,0),"Game?")


Regards

Claus B.


Sub Test works, but Sub TestX does not. TextX errors out on word "VLookup" for both lines.

Howard

Sub test()
Dim ws As Worksheet: Set ws = Sheets("Sheet1")
Dim rngLook As Range: Set rngLook = ws.Range("E1:F5")
Dim currName As String
Dim cellNum As Variant

currName = Range("B1")
cellNum = Application.VLookup(currName, rngLook, 2, False)
If IsError(cellNum) Then
MsgBox "Game?"
Else
MsgBox cellNum
End If
End Sub


Sub testX()
Dim ws As Worksheet: Set ws = Sheets("Sheet1")
Dim rngLook As Range: Set rngLook = ws.Range("E1:F5")
Dim currName As String

currName = Range("B1")
'IFERROR(VLOOKUP(H17,L2:Q75,J2,0),"Game?")

'MsgBox = Application.IfError(VLookup(currName, rngLook, 2, False), "Game?")
MsgBox = IfError(VLookup(currName, rngLook, 2, False), "Game?")
End Sub
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Vlookup result in a message box

Howard,
You can't 'assign' a return value to the MsgBox function. I'm not sure
you can do this even for the Prompt WITHIN the function but you can
try...

MsgBox Prompt:=Application.IfError(VLookup(currName, rngLook, 2,
False), "Game?")

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Vlookup result in a message box

Howard,
You can't 'assign' a return value to the MsgBox function. I'm not
sure you can do this even for the Prompt WITHIN the function but you
can try...

MsgBox Prompt:=Application.IfError(VLookup(currName, rngLook, 2,
False), "Game?")


A more conventional approach might be...

Dim sPrompt$
sPrompt = Application.IfError(VLookup(currName, rngLook, 2, False),
"Game?")

MsgBox sPrompt

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Vlookup result in a message box

Hi Howard,

Am Tue, 9 Sep 2014 08:14:34 -0700 (PDT) schrieb L. Howard:

'IFERROR(VLOOKUP(H17,L2:Q75,J2,0),"Game?")


if B1 is not available you get an error.
Try:

Sub testX()
Dim ws As Worksheet
Dim rngLook As Range
Dim currName As String
Dim Res As Variant

Set ws = Sheets("Sheet1")
Set rngLook = ws.Range("E1:F5")
currName = Range("B1")

With WorksheetFunction
If .CountIf(rngLook, currName) = 0 Then
Res = "Game?"
Else
Res = .VLookup("l", Range("E1:F5"), 2, False)
End If
End With

MsgBox Res
End Sub


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Vlookup result in a message box

Hi again,

Am Tue, 9 Sep 2014 08:14:34 -0700 (PDT) schrieb L. Howard:

'IFERROR(VLOOKUP(H17,L2:Q75,J2,0),"Game?")


use the find method instead:

Sub TestNew()
Dim wsh As Worksheet
Dim rngLook As Range, c As Range
Dim currName As String

Set wsh = Sheets("Sheet1")
Set rngLook = wsh.Range("E1:E5")
currName = wsh.Range("B1")

Set c = rngLook.Find(currName, LookIn:=xlValues, lookat:=xlWhole)
If Not c Is Nothing Then
MsgBox c.Offset(, 1)
Else
MsgBox "Game?"
End If
End Sub


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional


  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default Vlookup result in a message box


Thanks, guys.

Some good examples for me to refer to.

Howard

Reply
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 in vlookup - taking the result as array name SupperDuck Excel Worksheet Functions 2 June 2nd 07 11:05 AM
change from message box to result in cell DB Excel Programming 3 March 1st 07 10:30 PM
vlookup shows result one cell above the expected result Marie Excel Worksheet Functions 7 November 14th 06 02:52 AM
Countif result in message box M3Cobb[_9_] Excel Programming 4 June 12th 06 10:29 AM
vlookup based on random result returns incorrect result rickat Excel Worksheet Functions 1 December 6th 05 01:16 PM


All times are GMT +1. The time now is 06:04 PM.

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

About Us

"It's about Microsoft Excel"