Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Getting Details from 1 field


well, i do a lot of ASP, so i got very confused with VBA but basicly i
trying to get it so that the user enters in the ID number of a row tha
looks like this:

ID Firstname Lastname
1 John Smith
2 etc etc

so they would enter in "1" and "John" would appear as a result

i could do this with a for loop going down the whole id column(A) an
check against the variable that i have from the enteered ID i suppos
but there has to be a better way

This is my first piece of VBA but i know a little VB and a lot o
ASP(which is almost similar:p) so don't think im stupid just because
can't do this relatively simple piece of VB

-----------------------------------------------
~~ Message posted from http://www.ExcelTip.com
~~View and post usenet messages directly from http://www.ExcelForum.com

~~Now Available: Financial Statements.xls, a step by step guide to creating financial statements
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 391
Default Getting Details from 1 field

Use the VLOOKUP function
This allows you to look for an item in the first column
of a table, then return the value from aother column.
You could also use the Match then Index function.
Careful with VLookup as it raises an error where the item
isn't in the list.

On Error Resume Next
result = _
Application.WorksheetFunction.VLookup
(FindWhat,Table,col,False)
If Err.Number<0 then
Err.Clear
Result="Nothing Found"
End If
On Error goto 0


Patrick Molloy
Microsoft Excel MVP
-----Original Message-----

well, i do a lot of ASP, so i got very confused with VBA

but basicly im
trying to get it so that the user enters in the ID

number of a row that
looks like this:

ID Firstname Lastname
1 John Smith
2 etc etc

so they would enter in "1" and "John" would appear as a

result

i could do this with a for loop going down the whole id

column(A) and
check against the variable that i have from the enteered

ID i suppose
but there has to be a better way

This is my first piece of VBA but i know a little VB and

a lot of
ASP(which is almost similar:p) so don't think im stupid

just because I
can't do this relatively simple piece of VBA


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from

http://www.ExcelForum.com/

~~Now Available: Financial Statements.xls, a step by

step guide to creating financial statements
.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default Getting Details from 1 field

Hi Ghell,

Here is another way using "Application.Match".


Dim ID As Long, ret
ID = InputBox("Please Input ID")
ret = Application.Match(ID, Columns(1), 0)
If Not IsError(ret) Then MsgBox Cells(ret, 2).Value


--
Kind Regards
Colo
/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
Colo of 'The Road of The Cell Masters' :)

URL:http://www.interq.or.jp/sun/puremis/...astersLink.htm


/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/


"Ghell" wrote in message
...

well, i do a lot of ASP, so i got very confused with VBA but basicly im
trying to get it so that the user enters in the ID number of a row that
looks like this:

ID Firstname Lastname
1 John Smith
2 etc etc

so they would enter in "1" and "John" would appear as a result

i could do this with a for loop going down the whole id column(A) and
check against the variable that i have from the enteered ID i suppose
but there has to be a better way

This is my first piece of VBA but i know a little VB and a lot of
ASP(which is almost similar:p) so don't think im stupid just because I
can't do this relatively simple piece of VBA


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/

~~Now Available: Financial Statements.xls, a step by step guide to

creating financial statements

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 391
Default Getting Details from 1 field

This code will fail if the item isn't found. The functian
raises as error which you must trap.
Use
On Error Resume Next
'' you Application.WorksheetFunction.Match
IF Err.Number<0
Err.Clear
End If
On Error GoTo 0

Hint: I always call these functions within my own
function that avoids re-setting my error handlers, plus,
my function will always return a value...I can decide
what if there's no match, eg False, zero, -1, depending
on teh reason for the lookup

Patrick Molloy
Microsoft Excel MVP
-----Original Message-----
Hi Ghell,

Here is another way using "Application.Match".


Dim ID As Long, ret
ID = InputBox("Please Input ID")
ret = Application.Match(ID, Columns(1), 0)
If Not IsError(ret) Then MsgBox Cells(ret, 2).Value


--
Kind Regards
Colo
/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

_/_/_/
Colo of 'The Road of The Cell Masters' :)

URL:http://www.interq.or.jp/sun/puremis/colo/CellMastersL

ink.htm


/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

_/_/_/


"Ghell" wrote in

message
...

well, i do a lot of ASP, so i got very confused with

VBA but basicly im
trying to get it so that the user enters in the ID

number of a row that
looks like this:

ID Firstname Lastname
1 John Smith
2 etc etc

so they would enter in "1" and "John" would appear as

a result

i could do this with a for loop going down the whole

id column(A) and
check against the variable that i have from the

enteered ID i suppose
but there has to be a better way

This is my first piece of VBA but i know a little VB

and a lot of
ASP(which is almost similar:p) so don't think im

stupid just because I
can't do this relatively simple piece of VBA


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from

http://www.ExcelForum.com/

~~Now Available: Financial Statements.xls, a step by

step guide to
creating financial statements

.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default Getting Details from 1 field

Thanks Patrick,

Yes Application.WorksheetFunction.Match needs error trap,
But Application.Match is different from Application.WorksheetFunction.Match.
Application.Match doesn't raises an error, just return a value of the error.
I tend to use this one. :)

--
Kind Regards
Colo
/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
Colo of 'The Road of The Cell Masters' :)

URL:http://www.interq.or.jp/sun/puremis/...astersLink.htm


/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/


"Patrick Molloy" wrote in message
...
This code will fail if the item isn't found. The functian
raises as error which you must trap.
Use
On Error Resume Next
'' you Application.WorksheetFunction.Match
IF Err.Number<0
Err.Clear
End If
On Error GoTo 0

Hint: I always call these functions within my own
function that avoids re-setting my error handlers, plus,
my function will always return a value...I can decide
what if there's no match, eg False, zero, -1, depending
on teh reason for the lookup

Patrick Molloy
Microsoft Excel MVP
-----Original Message-----
Hi Ghell,

Here is another way using "Application.Match".


Dim ID As Long, ret
ID = InputBox("Please Input ID")
ret = Application.Match(ID, Columns(1), 0)
If Not IsError(ret) Then MsgBox Cells(ret, 2).Value


--
Kind Regards
Colo
/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

_/_/_/
Colo of 'The Road of The Cell Masters' :)

URL:http://www.interq.or.jp/sun/puremis/colo/CellMastersL

ink.htm


/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

_/_/_/


"Ghell" wrote in

message
...

well, i do a lot of ASP, so i got very confused with

VBA but basicly im
trying to get it so that the user enters in the ID

number of a row that
looks like this:

ID Firstname Lastname
1 John Smith
2 etc etc

so they would enter in "1" and "John" would appear as

a result

i could do this with a for loop going down the whole

id column(A) and
check against the variable that i have from the

enteered ID i suppose
but there has to be a better way

This is my first piece of VBA but i know a little VB

and a lot of
ASP(which is almost similar:p) so don't think im

stupid just because I
can't do this relatively simple piece of VBA


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from

http://www.ExcelForum.com/

~~Now Available: Financial Statements.xls, a step by

step guide to
creating financial statements

.




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Getting Details from 1 field


anyone notices how that original message thing is incredibly annoying?
anyway.. im still confused.. dont shout at me but can some1 give me
full macro code or something for it? as i said i am very new to VBA an
i dont really konw how most of tese objects wor

-----------------------------------------------
~~ Message posted from http://www.ExcelTip.com
~~View and post usenet messages directly from http://www.ExcelForum.com

~~Now Available: Financial Statements.xls, a step by step guide to creating financial statements
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Getting Details from 1 field

Colo's code basically does what you asked.

Sub Tester1()
Dim ID As Long, ret
ID = InputBox("Please Input ID")
ret = Application.Match(ID, Columns(1), 0)
If Not IsError(ret) Then
MsgBox Cells(ret, 2).Value
else
msgbox "Not Found"
end if
End Sub

--
Regards,
Tom Ogilvy


"Ghell" wrote in message
...

anyone notices how that original message thing is incredibly annoying?
anyway.. im still confused.. dont shout at me but can some1 give me a
full macro code or something for it? as i said i am very new to VBA and
i dont really konw how most of tese objects work


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/

~~Now Available: Financial Statements.xls, a step by step guide to

creating financial statements


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Getting Details from 1 field


yea, thanks colo, lil canges and i cna get it doing what i whant exactl
but i didnt think it would work when i saw it first :p

ill try toms before i modify it

but anyqway.. thanks all :

-----------------------------------------------
~~ Message posted from http://www.ExcelTip.com
~~View and post usenet messages directly from http://www.ExcelForum.com

~~Now Available: Financial Statements.xls, a step by step guide to creating financial statements
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
Hide "Show details" when right click on data field in Pivot Table Anh Tuan Excel Discussion (Misc queries) 0 June 18th 09 07:57 AM
Using List details within a sum forevertrying Excel Worksheet Functions 5 May 2nd 08 05:34 PM
I want to choose a name then other details will appear on other ce fLy Excel Discussion (Misc queries) 5 January 8th 07 07:01 AM
pivot table - hide details but show subtotal for calculated field tenneym Excel Discussion (Misc queries) 1 February 9th 05 03:07 AM
AVI details Greg[_12_] Excel Programming 1 September 17th 03 05:32 PM


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