Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
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 April 14th, 2008, 07:10 AM
Registered User
 
Join Date: Apr 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with VLookup and DATEVALUE in VBA

 I want to look up a date in column A in a file, using Vlookup, or some other function, and copy the data in col 2 of that row to another worksheet
2. The date string is dynamic, and I'm using the Datevalue function as input for VLookup, but I cannot get the correct syntax when i populate the formula in the cell using VBA.
If I enter the formula manually, the Vlookup is working correctly.
The VBA Code I use is:Selection.Formula = "=vlookup(DATEVALUE" & exp1 & ", 'D:/TA/[" & bookname & "]Sheet1'!A1:C1999,2,FALSE))"

exp1 is the derived date in the format mm/dd/yyyy. I have tried to set exp1 in different formats, but the value is not being converted to text.

On entering the formula manually (and recording in macro Recorder), the syntax is:-
vlookup(datevalue("6/16/2007"), 'D:/TA/[ABC.xls]Sheet1'!A1:C1999,2,FALSE))
This works correctly.
THe output of the VBA string given earlier is
=vlookup(datevalue(6/16/2007), 'D:/TA/[ABC.xls]Sheet1'!A1:C1999,2,FALSE)) The quotes around the date do not appear when the formula is inserted dynamically using VBA.
Excel DATEVALUE function is different from Datevalue function in VBA.
Another related issue is that On Manual Entry, when i run the macro, I get UpdateLinks:filename file selection msg box, even though I have added these two lines to the beginning of the macro.

Application.AskToUpdateLinks = False
Workbooks.Application. ActiveWorkbook.UpdateLinks = xlUpdateLinksNever


Thanks in advance for all help.

Sharad
 
Old April 14th, 2008, 08:46 PM
Authorized User
 
Join Date: Nov 2007
Posts: 48
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Sharadk74,

Try:
Range("A20").Formula = "=VLOOKUP(DATEVALUE(""6/16/2007""),'D:\TA\[ABC.xls]Sheet1'!A1:C1999,2,FALSE)"


Have a great day,
Stan

stanleydgromjr

Windows Vista Business and Excel 2003, 2007.
 
Old April 25th, 2008, 09:30 AM
Registered User
 
Join Date: Apr 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi, I managed to find the solution of this problem by using numberformat= "General" for the column of dates which I was looking up through VLookup. This prevented the need for using DATEVALUE function in VBA.
A related solution for inserting quote signs in a dynamic string is
Code:
mychr = Chr(34)
string =something+ mychr + " fixed text"
Rgds.,
Sharad






Similar Threads
Thread Thread Starter Forum Replies Last Post
Vlookup with VBA andygill Excel VBA 2 November 6th, 2008 06:44 PM
VLookup with Strings Problem dem1an Excel VBA 1 June 3rd, 2008 10:46 AM
Vlookup - Add entries to sheet that didnt match ttbhandari Excel VBA 2 September 21st, 2006 10:29 AM
VLookup, arrays, and worksheet names chp Excel VBA 0 April 7th, 2006 03:15 PM
character to range conversion for VLOOKUP gskoog Excel VBA 1 May 26th, 2004 05:10 AM





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