Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default VBA vlookup error depending on text string & quotation marks

The code causing me grief is as follows:

Dim acct as string, subacct as string

acct = CStr(Trim(Cells(i, clm_acct).Value))
subacct = CStr(Evaluate("=VLOOKUP(" & acct & ",'" & ThisWorkbook.Name &
"'!mapping,2,FALSE)"))

The referenced account numbers (variable acct) appear as text in the first
column of a table. Most of the account numbers are all numeric values, e.g.
345999, but some are a combination of numbers and letters, e.g. 345ABC.

When I call the procedure as is, I get an error, Error 2015, whenever acct
equals a combination of numbers and letters (345ABC). If I add quotation
marks to the function, e.g. Evaluate("=VLOOKUP(""" & acct & """,'" &
ThisWorkbook.Name & "'!mapping,2,FALSE)")), I no longer get an error with the
alphanumeric account numbers, but all the numeric only values (345999) now
result in an error.

While these two lines of code are the first instance of this problem in my
procedure, I use the Evaluate("=VLOOKUP()) in a number of places. I'm
looking for a solution that will save me a bunch of extra lines of code. One
workaround would be to add IF(ISERROR(() to the Evaluate(), but then I will
have to add that in every instance and it could really start to slow down the
procedure, plus make the code itself much larger. I thought if the cell
values were stored in text format and the acct variable was a string
variable, the vlookup would work for alpha and numeric values alike, but it
seems I was wrong. Does anyone know another solution, either with code or by
possibly changing the set up of the referenced worksheet?

Thanks,
Ben
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default VBA vlookup error depending on text string & quotation marks

I would think storing all the account numbers as text in the lookup table
would work. Just formatting the cells as text after the numbers are already
stored would not change them to text. You would need to edit each one and
store it as text or precede it with a single quote

for each cell in selection
if isnumber(cell.value) then
cell.value = "'" & cell.value
end if
Next

--
Regards,
Tom Ogilvy


"xlcharlie" wrote:

The code causing me grief is as follows:

Dim acct as string, subacct as string

acct = CStr(Trim(Cells(i, clm_acct).Value))
subacct = CStr(Evaluate("=VLOOKUP(" & acct & ",'" & ThisWorkbook.Name &
"'!mapping,2,FALSE)"))

The referenced account numbers (variable acct) appear as text in the first
column of a table. Most of the account numbers are all numeric values, e.g.
345999, but some are a combination of numbers and letters, e.g. 345ABC.

When I call the procedure as is, I get an error, Error 2015, whenever acct
equals a combination of numbers and letters (345ABC). If I add quotation
marks to the function, e.g. Evaluate("=VLOOKUP(""" & acct & """,'" &
ThisWorkbook.Name & "'!mapping,2,FALSE)")), I no longer get an error with the
alphanumeric account numbers, but all the numeric only values (345999) now
result in an error.

While these two lines of code are the first instance of this problem in my
procedure, I use the Evaluate("=VLOOKUP()) in a number of places. I'm
looking for a solution that will save me a bunch of extra lines of code. One
workaround would be to add IF(ISERROR(() to the Evaluate(), but then I will
have to add that in every instance and it could really start to slow down the
procedure, plus make the code itself much larger. I thought if the cell
values were stored in text format and the acct variable was a string
variable, the vlookup would work for alpha and numeric values alike, but it
seems I was wrong. Does anyone know another solution, either with code or by
possibly changing the set up of the referenced worksheet?

Thanks,
Ben

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default VBA vlookup error depending on text string & quotation marks

Thanks Tom. Adding the apostrophe did the trick.

"Tom Ogilvy" wrote:

I would think storing all the account numbers as text in the lookup table
would work. Just formatting the cells as text after the numbers are already
stored would not change them to text. You would need to edit each one and
store it as text or precede it with a single quote

for each cell in selection
if isnumber(cell.value) then
cell.value = "'" & cell.value
end if
Next

--
Regards,
Tom Ogilvy


"xlcharlie" wrote:

The code causing me grief is as follows:

Dim acct as string, subacct as string

acct = CStr(Trim(Cells(i, clm_acct).Value))
subacct = CStr(Evaluate("=VLOOKUP(" & acct & ",'" & ThisWorkbook.Name &
"'!mapping,2,FALSE)"))

The referenced account numbers (variable acct) appear as text in the first
column of a table. Most of the account numbers are all numeric values, e.g.
345999, but some are a combination of numbers and letters, e.g. 345ABC.

When I call the procedure as is, I get an error, Error 2015, whenever acct
equals a combination of numbers and letters (345ABC). If I add quotation
marks to the function, e.g. Evaluate("=VLOOKUP(""" & acct & """,'" &
ThisWorkbook.Name & "'!mapping,2,FALSE)")), I no longer get an error with the
alphanumeric account numbers, but all the numeric only values (345999) now
result in an error.

While these two lines of code are the first instance of this problem in my
procedure, I use the Evaluate("=VLOOKUP()) in a number of places. I'm
looking for a solution that will save me a bunch of extra lines of code. One
workaround would be to add IF(ISERROR(() to the Evaluate(), but then I will
have to add that in every instance and it could really start to slow down the
procedure, plus make the code itself much larger. I thought if the cell
values were stored in text format and the acct variable was a string
variable, the vlookup would work for alpha and numeric values alike, but it
seems I was wrong. Does anyone know another solution, either with code or by
possibly changing the set up of the referenced worksheet?

Thanks,
Ben

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
Quotation Marks as Text Kelly C Excel Discussion (Misc queries) 2 August 3rd 08 06:20 PM
Generating text surrounded by quotation marks AaronQRules (a.k.a. Jeff) Excel Discussion (Misc queries) 5 July 30th 07 08:12 PM
After exporting how do I remove quotation marks from text cells Marty G Excel Discussion (Misc queries) 0 July 29th 05 02:54 AM
Passing string arguments that have quotation marks in them Caro-Kann Defence[_2_] Excel Programming 2 April 21st 05 03:26 PM
How do I concatenate text that actually contains quotation marks? Excel Distress Excel Worksheet Functions 3 April 15th 05 02:23 PM


All times are GMT +1. The time now is 04:22 AM.

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"