Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default vlookup if not in Table

I need to lookup a Table to find values, but somtimes my entry is not present
and the function returns '#NA'. In this case I want a blank in column M,
otherwise some function.

The following code does not run and has an error somewhere in the
ActiveCell.Formula.
Thanks for any help.

Range("M2").Select
ActiveCell.Formula =
_"=IF((VLOOKUP(B2,'LookupTable'!$A$1:$B$100,1,FALS E)="#NA"),"",IF(G20,(G2-J2)*E2/G2,""))"
With ActiveSheet
.Range("M2").AutoFill Destination:=Range("M" & lastrow),
Type:=xlFillDefault
End With

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default vlookup if not in Table

Try doubling up on the double quotes and using =if(iserror(

ActiveCell.Formula = _
"=IF(iserror(VLOOKUP(B2,'LookupTable'!$A$1:$B$100, 1,FALSE)),""""," _
& "IF(G20,(G2-J2)*E2/G2,""""))"

But since you're only checking column A, you could use =if(iserror(match(...)))

ActiveCell.Formula = _
"=IF(iserror(match(B2,'LookupTable'!$A$1:$a$100,0) ),""""," _
& "IF(G20,(G2-J2)*E2/G2,""""))"





Kanga 85 wrote:

I need to lookup a Table to find values, but somtimes my entry is not present
and the function returns '#NA'. In this case I want a blank in column M,
otherwise some function.

The following code does not run and has an error somewhere in the
ActiveCell.Formula.
Thanks for any help.

Range("M2").Select
ActiveCell.Formula =
_"=IF((VLOOKUP(B2,'LookupTable'!$A$1:$B$100,1,FALS E)="#NA"),"",IF(G20,(G2-J2)*E2/G2,""))"
With ActiveSheet
.Range("M2").AutoFill Destination:=Range("M" & lastrow),
Type:=xlFillDefault
End With


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default vlookup if not in Table

Thanks Dave and Jim

"Dave Peterson" wrote:

Try doubling up on the double quotes and using =if(iserror(

ActiveCell.Formula = _
"=IF(iserror(VLOOKUP(B2,'LookupTable'!$A$1:$B$100, 1,FALSE)),""""," _
& "IF(G20,(G2-J2)*E2/G2,""""))"

But since you're only checking column A, you could use =if(iserror(match(...)))

ActiveCell.Formula = _
"=IF(iserror(match(B2,'LookupTable'!$A$1:$a$100,0) ),""""," _
& "IF(G20,(G2-J2)*E2/G2,""""))"





Kanga 85 wrote:

I need to lookup a Table to find values, but somtimes my entry is not present
and the function returns '#NA'. In this case I want a blank in column M,
otherwise some function.

The following code does not run and has an error somewhere in the
ActiveCell.Formula.
Thanks for any help.

Range("M2").Select
ActiveCell.Formula =
_"=IF((VLOOKUP(B2,'LookupTable'!$A$1:$B$100,1,FALS E)="#NA"),"",IF(G20,(G2-J2)*E2/G2,""))"
With ActiveSheet
.Range("M2").AutoFill Destination:=Range("M" & lastrow),
Type:=xlFillDefault
End With


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default vlookup if not in Table

While I would be more inclined to use a countif to see if your value exists
you can use vlookup. What you want to do is to the the ISNA function to check
the return value something like this...

ActiveCell.Formula =
_"=IF(ISNA(VLOOKUP(B2,'LookupTable'!$A$1:$B$100,1, FALSE)),"",IF(G20,(G2-J2)*E2/G2,""))"

--
HTH...

Jim Thomlinson


"Kanga 85" wrote:

I need to lookup a Table to find values, but somtimes my entry is not present
and the function returns '#NA'. In this case I want a blank in column M,
otherwise some function.

The following code does not run and has an error somewhere in the
ActiveCell.Formula.
Thanks for any help.

Range("M2").Select
ActiveCell.Formula =
_"=IF((VLOOKUP(B2,'LookupTable'!$A$1:$B$100,1,FALS E)="#NA"),"",IF(G20,(G2-J2)*E2/G2,""))"
With ActiveSheet
.Range("M2").AutoFill Destination:=Range("M" & lastrow),
Type:=xlFillDefault
End With

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default vlookup if not in Table

Sorry as Dave points out you need the double quotes...

ActiveCell.Formula =
_"=IF(ISNA(VLOOKUP(B2,'LookupTable'!$A$1:$B$100,1, FALSE)),"""",IF(G20,(G2-J2)*E2/G2,""""))"

or

ActiveCell.Formula =
_"=IF(CountIf('LookupTable'!$A$1:$B$100,B2)=0,"""" ,IF(G20,(G2-J2)*E2/G2,""""))"
--
HTH...

Jim Thomlinson


"Jim Thomlinson" wrote:

While I would be more inclined to use a countif to see if your value exists
you can use vlookup. What you want to do is to the the ISNA function to check
the return value something like this...

ActiveCell.Formula =
_"=IF(ISNA(VLOOKUP(B2,'LookupTable'!$A$1:$B$100,1, FALSE)),"",IF(G20,(G2-J2)*E2/G2,""))"

--
HTH...

Jim Thomlinson


"Kanga 85" wrote:

I need to lookup a Table to find values, but somtimes my entry is not present
and the function returns '#NA'. In this case I want a blank in column M,
otherwise some function.

The following code does not run and has an error somewhere in the
ActiveCell.Formula.
Thanks for any help.

Range("M2").Select
ActiveCell.Formula =
_"=IF((VLOOKUP(B2,'LookupTable'!$A$1:$B$100,1,FALS E)="#NA"),"",IF(G20,(G2-J2)*E2/G2,""))"
With ActiveSheet
.Range("M2").AutoFill Destination:=Range("M" & lastrow),
Type:=xlFillDefault
End With



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default vlookup if not in Table

Watch that =countif() version. You'll only want to look at A1:A100.



Jim Thomlinson wrote:

Sorry as Dave points out you need the double quotes...

ActiveCell.Formula =
_"=IF(ISNA(VLOOKUP(B2,'LookupTable'!$A$1:$B$100,1, FALSE)),"""",IF(G20,(G2-J2)*E2/G2,""""))"

or

ActiveCell.Formula =
_"=IF(CountIf('LookupTable'!$A$1:$B$100,B2)=0,"""" ,IF(G20,(G2-J2)*E2/G2,""""))"
--
HTH...

Jim Thomlinson

"Jim Thomlinson" wrote:

While I would be more inclined to use a countif to see if your value exists
you can use vlookup. What you want to do is to the the ISNA function to check
the return value something like this...

ActiveCell.Formula =
_"=IF(ISNA(VLOOKUP(B2,'LookupTable'!$A$1:$B$100,1, FALSE)),"",IF(G20,(G2-J2)*E2/G2,""))"

--
HTH...

Jim Thomlinson


"Kanga 85" wrote:

I need to lookup a Table to find values, but somtimes my entry is not present
and the function returns '#NA'. In this case I want a blank in column M,
otherwise some function.

The following code does not run and has an error somewhere in the
ActiveCell.Formula.
Thanks for any help.

Range("M2").Select
ActiveCell.Formula =
_"=IF((VLOOKUP(B2,'LookupTable'!$A$1:$B$100,1,FALS E)="#NA"),"",IF(G20,(G2-J2)*E2/G2,""))"
With ActiveSheet
.Range("M2").AutoFill Destination:=Range("M" & lastrow),
Type:=xlFillDefault
End With


--

Dave Peterson
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 Table - with L/U value as '100 JMay Excel Discussion (Misc queries) 2 April 1st 09 04:32 PM
Vlookup Table Help Greg New Users to Excel 2 June 3rd 08 05:05 AM
Vlookup table Joe Excel Discussion (Misc queries) 3 January 23rd 08 07:32 PM
Table with VLOOKUP? Tatebana Excel Discussion (Misc queries) 5 February 1st 07 03:31 PM
Vlookup info being used without vlookup table attached? Excel Worksheet Functions 0 January 25th 05 10:43 AM


All times are GMT +1. The time now is 12:17 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"