Function is not functioning

  • Thread starter Thread starter cmoore
  • Start date Start date
C

cmoore

Why wont this work? Ideas on how to make it work?


Function Molecular_Wt(Component)

Range("C2:AI4").Select

Selection.Find(What:=Component, After:=ActiveCell,
LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext
_
MatchCase:=False).Activate

ActiveCell.Offset(0, 1).Select

Molecular_Wt = ActiveCell.Value

End Functio
 
Try to run in debug > step into (or F8). This will run the
code line by line, and help you locate the problem.

Nikos Y. (nyannaco at in dot gr)
 
I think this line should be changed :-

Molecular_Wt = ActiveCell.Value
to
ActiveCell.Value = Molecular_Wt
 
Sorry ! just realised that we cannot use Find in a function.
I think your best plan would be to convert your data to a lookup tabl
and make your function something like :-

'------------------------------------------------
Function Molecular_Wt(component)
Molecular_Wt = Application.WorksheetFunction.VLookup(component
Range("A1:B100"), 2, False)
End Function
'----------------------------------------------------
 
Thank you BrianB. That solution works. Although I do think the Fin
will work in a Function if it is formated correctly.

This was in an example in the Excel Help Files... But it doesn't wor
either?!@#@?

Function LastRow(sh As Worksheet)
On Error Resume Next
LastRow = sh.Cells.Find(What:="Bromine", _
After:=sh.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Functio
 
When the function is called from a worksheet cell, then Find method doesn't work
in xl2k or previous.

It works fine in xl2002. (don't know if it was changed again in xl2003).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Find & Replace in VB macro 1
If... then... Else statement 2
Using Find in a macro 2
How to remove a character from the first index? 3
Loop 1
LOOPS IN MACROS 3
Do until loop 6
Macro to find and paste rows 5

Back
Top