Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default sub for reading

I have a sheet, that starts in A56, B56 to A208,B208, , in other sheet,
that's the user side, the user enter the Postal code in cell called
PCODE... What I need to do, is able to read, the second column, because,
the first one is the Postal Code, the second is the Zone, I need to
extract this information, using the entry in the PCODE, then I will
manipulate this information in my main program... but forget about the
main, in working fine, I just need to get the information...

A B
A0B 10
A0H 11
etc...

I need the B column, base in the A

Thanks for the ideas

Fernando

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default sub for reading

use Vlookup

Using a worksheet formula

=Vlookup(pcode,Sheet1!$A$56:$B$208,2,false)

you can do it with VBA as well

res = Application.Vlookup(Range("pcode").Value,
Range("Sheet1!A56:B208"),2,False)

--
Regards,
Tom Ogilvy

"Fernando Duran" wrote in message
...
I have a sheet, that starts in A56, B56 to A208,B208, , in other sheet,
that's the user side, the user enter the Postal code in cell called
PCODE... What I need to do, is able to read, the second column, because,
the first one is the Postal Code, the second is the Zone, I need to
extract this information, using the entry in the PCODE, then I will
manipulate this information in my main program... but forget about the
main, in working fine, I just need to get the information...

A B
A0B 10
A0H 11
etc...

I need the B column, base in the A

Thanks for the ideas

Fernando



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default sub for reading

Hi Tom, thanks for your answer...I used the formula inside of a test
Sub, but I got an error "run time error 1004" if i'm correct.
But I also I forget to tell you, that column A, it's like this

A0A-B0C
B1A
B2B-C3Z
that's wright, it uses ranges, what I was planning to do, was to cut the
last and use only the first part. But that I can fixe, but any ideas
what in a small line like that, I get that error?
res = Application.VLookup(Range("Sheet1!PCODE").Value,
Range("A56:B208"), 2, False)
Tom Ogilvy wrote:

use Vlookup

Using a worksheet formula

=Vlookup(pcode,Sheet1!$A$56:$B$208,2,false)

you can do it with VBA as well

res = Application.Vlookup(Range("pcode").Value,
Range("Sheet1!A56:B208"),2,False)


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default sub for reading

Testing from the immediate window

res = Application.VLookup(Range("Sheet1!PCODE").Value, Range("A56:B208"), 2,
False)
? res
Error 2042

Error 2042 is the same as #N/A in the worksheet meaning no match.

If I fill column B with the formula

="B"&row()
and in column A, sequentially number the cells (1, 2, 3, etc)

and PCode contains 3

res = Application.VLookup(Range("Sheet1!PCODE").Value, Range("A56:B208"), 2,
False)
? res
B58

then it returns the value in cell B58 ( A56 = 1, A57 = 2, A58 = 3)

so the match is to row 58.

So it works for me.

dim res as Variant
res = Application.VLookup(Range("Sheet1!PCODE").Value, Range("A56:B208"), 2,
False)
if iserror(res) then
msgbox "Not Found"
Else
msgbox "Results is " & res
End if

You would need to change the 4th argument to True if you want to match a
range. See help in Excel itself for how Vlookup operates.

Don't know why you would get a 1004 error. (if you use
WorksheetFunction.Vlookup, then this raises an 1004 error when no match is
made).

--
Regards,
Tom Ogilvy

"Fernando Duran" wrote in message
...
Hi Tom, thanks for your answer...I used the formula inside of a test
Sub, but I got an error "run time error 1004" if i'm correct.
But I also I forget to tell you, that column A, it's like this

A0A-B0C
B1A
B2B-C3Z
that's wright, it uses ranges, what I was planning to do, was to cut the
last and use only the first part. But that I can fixe, but any ideas
what in a small line like that, I get that error?
res = Application.VLookup(Range("Sheet1!PCODE").Value,
Range("A56:B208"), 2, False)
Tom Ogilvy wrote:

use Vlookup

Using a worksheet formula

=Vlookup(pcode,Sheet1!$A$56:$B$208,2,false)

you can do it with VBA as well

res = Application.Vlookup(Range("pcode").Value,
Range("Sheet1!A56:B208"),2,False)




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default sub for reading

oK. Tom, I'll give a try, ASAp

Thanks again



Tom Ogilvy wrote:

Testing from the immediate window

res = Application.VLookup(Range("Sheet1!PCODE").Value, Range("A56:B208"), 2,
False)
? res
Error 2042

Error 2042 is the same as #N/A in the worksheet meaning no match.

If I fill column B with the formula

="B"&row()
and in column A, sequentially number the cells (1, 2, 3, etc)

and PCode contains 3

res = Application.VLookup(Range("Sheet1!PCODE").Value, Range("A56:B208"), 2,
False)
? res
B58

then it returns the value in cell B58 ( A56 = 1, A57 = 2, A58 = 3)

so the match is to row 58.

So it works for me.

dim res as Variant
res = Application.VLookup(Range("Sheet1!PCODE").Value, Range("A56:B208"), 2,
False)
if iserror(res) then
msgbox "Not Found"
Else
msgbox "Results is " & res
End if

You would need to change the 4th argument to True if you want to match a
range. See help in Excel itself for how Vlookup operates.

Don't know why you would get a 1004 error. (if you use
WorksheetFunction.Vlookup, then this raises an 1004 error when no match is
made).

--
Regards,
Tom Ogilvy

"Fernando Duran" wrote in message
...

Hi Tom, thanks for your answer...I used the formula inside of a test
Sub, but I got an error "run time error 1004" if i'm correct.
But I also I forget to tell you, that column A, it's like this

A0A-B0C
B1A
B2B-C3Z
that's wright, it uses ranges, what I was planning to do, was to cut the
last and use only the first part. But that I can fixe, but any ideas
what in a small line like that, I get that error?
res = Application.VLookup(Range("Sheet1!PCODE").Value,
Range("A56:B208"), 2, False)
Tom Ogilvy wrote:


use Vlookup

Using a worksheet formula

=Vlookup(pcode,Sheet1!$A$56:$B$208,2,false)

you can do it with VBA as well

res = Application.Vlookup(Range("pcode").Value,
Range("Sheet1!A56:B208"),2,False)





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
Reading a formula Kell2604 Excel Discussion (Misc queries) 5 November 4th 08 10:43 PM
reading email geedubb Excel Discussion (Misc queries) 3 May 24th 08 01:12 AM
reading from SQL Texas Tonie[_2_] Excel Discussion (Misc queries) 0 November 9th 07 10:59 PM
Reading XML Ajit Excel Discussion (Misc queries) 1 October 2nd 07 10:54 PM
I need help reading time sydolly Excel Discussion (Misc queries) 3 September 9th 05 11:05 PM


All times are GMT +1. The time now is 12:45 PM.

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"