Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
jag jag is offline
external usenet poster
 
Posts: 1
Default Create function to find a value in an array in seperate worksheet

I am looking to create a VB fuction to use a stock reference in a cell
(A) from one workbook, to reference the correct column of information
corresponding to cell A and return the contents of the cell based its
3rd element and the 4th element.
Example:
Sheet1
A
B C
IBM
1/10 112.34

=ATMSTRIKE(A1,B1,C1) would return from the "B" column in Sheet2 "WIB
US 1/10 C110 Equity" by looking up 3 things 1) IBM,
2) the "1/10" as the 3rd element
3) and the smallest absolute value of the difference between
the number in the 4th element and number in C1
which is 112.34

Sheet2
A
B C
dell ibm msft
DLQ US 11 P22 Equity IBM US 6 C75 Equity MSQ US 6 C24
Equity
DLQ US 11 P23 Equity IBM US 6 C80 Equity MSQ US 6 C25
Equity
VPZ US 1 C10 Equity IBM US 7 P90 Equity MSQ US 7
C22.50 Equity
VPZ US 1 C15 Equity IBM US 10 P90 Equity MSQ US 7
C24 Equity
VPZ US 1 C17.50 Equity IBM US 1 P110 Equity MSQ US 1 C40
Equity
WDQ US 1/10 C17.50 Equity IBM US 1 P115 Equity MSQ US 1 C42.50
Equity
WDQ US 1/10 C20 Equity WIB US 1/10 C100 Equity WMF US 1/10
C35 Equity
WDQ US 1/10 C25 Equity WIB US 1/10 C110 Equity WMF US 1/10
C37.50 Equity
WIB US 1/10 C120 Equity WMF US 1/10
C40 Equity
WIB US 1/10 C125 Equity

I would assume you would use multiple functions to create one such as:

Function ExtractElement (txt,n,Seperator)
Dim AllElements As Variant
AllElements = Split(txt,Seperator)
ExtractElement = AllElements(n-1)
End Function

and also Match and Loops, just having hard time putting it all
together

Thanks in advance,
JAG
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Create function to find a value in an array in seperate worksheet

Function ATMSTRIKE(Company As String, _
Fraction As String, Equity As Single)

With Sheets("Sheet2")
'get company column, search for company name in row 1
Set c = .Rows(1).Find(what:=Company, _
LookIn:=xlValues, lookat:=xlWhole)
If Not c Is Nothing Then
LastRow = .Cells(Rows.Count, c.Column).End(xlUp).Row
RowCount = 2
ATMSTRIKE = ""
Do While RowCount <= LastRow
Element = .Cells(RowCount, c.Column)
'split fields by spaces
SplitElement = Split(Element)
SplitFraction = SplitElement(2)
SplitEquity = SplitElement(3)
'remove first letter and convert to a number
SplitEquity = Val(Mid(SplitEquity, 2))
If SplitFraction = Fraction Then
If BestElement = "" Then
BestEquity = SplitEquity
ATMSTRIKE = Element
Else
If Abs(SplitEquity - Equity) < _
Abs(BestEquity - Equity) Then

BestEquity = SplitEquity
ATMSTRIKE = Element

End If
End If
End If
RowCount = RowCount + 1
Loop
Else
ATMSTRIKE = "Company: " & Company & " Not found"
End If
End With

End Function


"jag" wrote:

I am looking to create a VB fuction to use a stock reference in a cell
(A) from one workbook, to reference the correct column of information
corresponding to cell A and return the contents of the cell based its
3rd element and the 4th element.
Example:
Sheet1
A
B C
IBM
1/10 112.34

=ATMSTRIKE(A1,B1,C1) would return from the "B" column in Sheet2 "WIB
US 1/10 C110 Equity" by looking up 3 things 1) IBM,
2) the "1/10" as the 3rd element
3) and the smallest absolute value of the difference between
the number in the 4th element and number in C1
which is 112.34

Sheet2
A
B C
dell ibm msft
DLQ US 11 P22 Equity IBM US 6 C75 Equity MSQ US 6 C24
Equity
DLQ US 11 P23 Equity IBM US 6 C80 Equity MSQ US 6 C25
Equity
VPZ US 1 C10 Equity IBM US 7 P90 Equity MSQ US 7
C22.50 Equity
VPZ US 1 C15 Equity IBM US 10 P90 Equity MSQ US 7
C24 Equity
VPZ US 1 C17.50 Equity IBM US 1 P110 Equity MSQ US 1 C40
Equity
WDQ US 1/10 C17.50 Equity IBM US 1 P115 Equity MSQ US 1 C42.50
Equity
WDQ US 1/10 C20 Equity WIB US 1/10 C100 Equity WMF US 1/10
C35 Equity
WDQ US 1/10 C25 Equity WIB US 1/10 C110 Equity WMF US 1/10
C37.50 Equity
WIB US 1/10 C120 Equity WMF US 1/10
C40 Equity
WIB US 1/10 C125 Equity

I would assume you would use multiple functions to create one such as:

Function ExtractElement (txt,n,Seperator)
Dim AllElements As Variant
AllElements = Split(txt,Seperator)
ExtractElement = AllElements(n-1)
End Function

and also Match and Loops, just having hard time putting it all
together

Thanks in advance,
JAG

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
How to create automated find of common names in seperate columns? Exceldummy Excel Discussion (Misc queries) 0 July 22nd 09 06:45 AM
How do I display the result of a function on seperate worksheet e. Beth Excel Worksheet Functions 3 July 15th 08 05:30 AM
Worksheet Function to Create Array of Size n with values x Through Dial222 Excel Discussion (Misc queries) 1 December 6th 07 11:21 AM
Using VBA - create array - parse values - find differences eholz1 Excel Programming 2 September 18th 07 10:35 PM
want to create a template and update in seperate worksheet lata New Users to Excel 0 February 23rd 05 07:21 AM


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