View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
J Williams J Williams is offline
external usenet poster
 
Posts: 2
Default Parsing cell formula to return associated value

I have 2 sheets in my workbook. Sheet1 is a stock list (item and price in
adjacent column):

A B
1 Screen 200
2 Speakers 50
3 Keyboard 20
etc.

Sheet2 contains items manually selected from Sheet1 in column A:

A B
1 =Sheet1!A1 ??
2 =Sheet1!A99 ??

I want B1 on Sheet2 to contain the price associated with the formula in A1.
I can't do a straightforward drag cell formula from A1 to B1 (to get
=Sheet1!B1) because the user can change the cell reference in A1 and I want
B1 to automatically update with the correct price. Similarly B2 should
contain the price associated with the formula in A2.

I think this requires a user-defined function, e.g. B1 would contain
=getPrice(A1).

Function getPrice(itemCell As range) As Integer
item = itemCell.Formula
End Function

and parse the formula to get the price from Sheet1, same row, column+1, but
don't know how to proceed. Any help much appreciated. Cheers.