Wrox Programmer Forums
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 15th, 2005, 12:59 PM
Authorized User
 
Join Date: Jan 2005
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default Inputbox and Formulas

Hi, to all Gurus!
              I wrote the following codes with Inputbox to search from a table , combining it with a vlookup formula.
            I want the answer to be displayed on Range("b2") of the active worksheet.
    CODEs:
   Dim Num as Integer
   Num = Inputbox ("Please enter the search number")
   Worksheets("sheet1).range("B2").formula = "=vlookup(Num, Range(K2:M6),2)

     Each time I type in the number in the Inputbox to look up the resultant figure, Range("B2") displays "#Name?"

     Why is this so? I am using MS Office 2000 (version) .
     Can anybody help?
     Appreciate your kind assistance.
[u]</u>
 
Old February 15th, 2005, 02:36 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 150
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try this:

"=vlookup(2, K2:M6,2)"

oops! This should do it:

Formula = "=vlookup(" & Num & ", K2:M6,2)"
 
Old February 15th, 2005, 03:17 PM
Authorized User
 
Join Date: Jun 2003
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You're not appending the "Num" variable correctly to your function string. You are retrieving a value from your InputBox correctly, but when you subsequently build your function string you don't append, so Excel will assume that "Num" is a named range (which obviously doesn't exist.

Try:

Code:
  Dim Num as Integer
  Num = Inputbox ("Please enter the search number")
  Worksheets("sheet1").range("B2").formula = "=vlookup(" & Num & ", Range(K2:M6),2)"
 
Old February 17th, 2005, 01:39 AM
Authorized User
 
Join Date: Jan 2005
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for both your excellent help. I don't get that many good books here to guide me on such a simple approach. Your explanations clear up a misunderstood information on the use of operator " & ". It has to be spaced before and after
"Num".





Similar Threads
Thread Thread Starter Forum Replies Last Post
Formulas Juan0214 Access 4 July 2nd, 2008 02:04 PM
Need help with time formulas pfreire727 Excel VBA 1 February 12th, 2006 07:41 PM
Format inputbox jesseleon Access VBA 2 October 5th, 2005 03:14 PM
InputBox Misbehaving bph Access 10 March 4th, 2004 01:09 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.