Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
M H M H is offline
external usenet poster
 
Posts: 28
Default Use of LOOKUP in VBA

Hi there,
I have created a function like this:

Option Explicit
Option Base 1

Public Function DeltaG(sInput As String)

Dim siRNA, NN() As String
Dim iNumofNN As Integer
Dim rNN As Range
Dim dG, dGNN As Single

With Worksheets("EnergyTable")
.Activate
rNN = .Range("B5:H20")
dG = .Range("C22").Value + .Range("C24").Value
End With

siRNA = sInput
For iNumofNN = 1 To Len(siRNA) - 1
NN(iNumofNN) = Mid(siRNA, iNumofNN, 2)
dGNN = Application.WorksheetFunction.VLookup(NN(iNumofNN) , rNN, 2,
False)
dG = dG + dGNN
Next

DeltaG = dG
End Function

What does it do is to chop a string into an array of 2-letter strings,
match each short string to a table with all possible combinations of
2-letter strings for getting a value from the next column. The readout
of the function would be the sum of the values corresponding to the
array elements.

The function simply does not work as I expected, but I could not figure
out where the problem hides. Please help. Thanks.

Here is the link to my sample workbook:
http://boz094.ust.hk/EnergyTable.xls

*** Sent via Developersdex http://www.developersdex.com ***
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Use of LOOKUP in VBA

MH,

I made some revisions/corrections...
The rNN range had not been "Set".
The NN() array had not been dimensioned.
Some data types were changed.
It is past time for bed here and I will leave the
revised code for your perusal.
'------------------
Public Function DeltaG(sInput As String) As Double
Dim siRNA As String
Dim NN() As String
Dim iNumofNN As Long
Dim rNN As Excel.Range
Dim dG As Double
Dim dGNN As Double

With Worksheets("EnergyTable")
.Activate
Set rNN = .Range("B5:H20")
dG = .Range("C22").Value + .Range("C24").Value
End With

siRNA = sInput
ReDim NN(1 To Len(siRNA) - 1)

For iNumofNN = 1 To Len(siRNA) - 1
NN(iNumofNN) = Mid$(siRNA, iNumofNN, 2)
dGNN = Application.WorksheetFunction.VLookup(NN(iNumofNN) , rNN, 2, False)
dG = dG + dGNN
Next
DeltaG = dG
End Function
'---------------------
Jim Cone
San Francisco, USA



"M H" wrote in message
...
Hi there,
I have created a function like this:
Option Explicit
Option Base 1
Public Function DeltaG(sInput As String)
Dim siRNA, NN() As String
Dim iNumofNN As Integer
Dim rNN As Range
Dim dG, dGNN As Single
With Worksheets("EnergyTable")
.Activate
rNN = .Range("B5:H20")
dG = .Range("C22").Value + .Range("C24").Value
End With
siRNA = sInput
For iNumofNN = 1 To Len(siRNA) - 1
NN(iNumofNN) = Mid(siRNA, iNumofNN, 2)
dGNN = Application.WorksheetFunction.VLookup(NN(iNumofNN) , rNN, 2,
False)
dG = dG + dGNN
Next
DeltaG = dG
End Function

What does it do is to chop a string into an array of 2-letter strings,
match each short string to a table with all possible combinations of
2-letter strings for getting a value from the next column. The readout
of the function would be the sum of the values corresponding to the
array elements.
The function simply does not work as I expected, but I could not figure
out where the problem hides. Please help. Thanks.
Here is the link to my sample workbook:
  #3   Report Post  
Posted to microsoft.public.excel.programming
M H M H is offline
external usenet poster
 
Posts: 28
Default Use of LOOKUP in VBA

Bravo, Jim!
Much thanks!!



*** Sent via Developersdex http://www.developersdex.com ***
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Use of LOOKUP in VBA


Your link doesn't work for m

--
Kaa
-----------------------------------------------------------------------
Kaak's Profile: http://www.excelforum.com/member.php...nfo&userid=751
View this thread: http://www.excelforum.com/showthread.php?threadid=39710

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
lookup help. lookup result based on data in 2 columns lcc Excel Worksheet Functions 3 April 6th 10 01:20 PM
LOOKUP FUNCTION? (LOOKUP VALUE BEING A TIME RENERATED FROM A FORMU JCC Excel Discussion (Misc queries) 5 June 26th 09 09:15 PM
Lookup looks to the prior column if zero appears in the lookup col kenbquik Excel Discussion (Misc queries) 2 March 12th 09 03:41 AM
Join 2 Lists - Lookup value in 1 list & use result in 2nd lookup JBush Excel Worksheet Functions 3 January 3rd 07 11:14 PM
Sumproduct - Condition based on lookup of a Lookup Hari Excel Discussion (Misc queries) 12 May 31st 06 09:28 AM


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