index > Visual Basic for Applications (VBA) > How to write a 'Find function' code in VBA for Excel

How to write a 'Find function' code in VBA for Excel


Hi,

I wrote this code in hope that it would look for the text string 'c6' which is found in one of the cells in range A1:C6. In the end I want it to assign the cell's address to a variable but one thing first.

Function finn(x)
'x = Range(A1:C6)
Dim y, q

y = x

q = Application.WorksheetFunction.Find(c6, y)
MsgBox q

End Function

But it won't work!

Anyone that knows how to write this properly?

Grateful for help on this

\Jonas




JS
Jonas.S
You could use a foreach construct

eg
dim cel as Range
foreach cel in Range(A1:C6)
if x = "c6" then
do whatever
end if
next cel

that should find it for you
***The syntax isn't perfect, its only a rough guide
nialljsmith
Thanks for the replay. Your start combined with some additional studie of the help solved my problem.


JS
Jonas.S
reply 3

You can use google to search for other answers

 

More Articles

• Charts in Excel
• MS Access User Defined Permissions
• Printing graphic file
• Getting Data of HTML page
• Disable "Unprotect Document" in Tools Menu Item
• File name - VBA for powerpoint
• Special action required for one item in a listbox
• VBA, Access, & SQL Server
• Access Project and View Record source
• Source Object as a query
Welcome to Bokebb   New Update   Joins the collection  
 

New Articles

• name worksheet
• API (HLLAPI) errors when accessed from V
• Difference between FORMS and CONTROL TOO
• Linking to an Oracle DB via MSAccess/VBA
• SaveAs question
• Refer to another module tag
• VBA, Access, & SQL Server
• Colored Named Ranges
• Array lengths
• Bound form
• Copy text from textbox to clipboard?
• Derek and/or Cindy
• Error with Data refreshing in the backgr
• XP Login ID
• Excel - squares appear when sending info

Hot Articles

• ActiveX RICHTX32.OCX
• Setting Password Char in InputBox?
• Positioning DialogSheets
• Outlook new Mail item
• Acces functions in my ouwn services appl
• Aliases !!!
• How to pop data from a table in MS Acces
• cutting down this code? help?
• VBA TaskBox (Windows XP) & HTML Mult
• Security of source code in vba
• VBA Code to save Excel w Name including
• Hide/unhide
• extract office file's title into excel
• How to fill worksheets with HTML
• VBA books

Recommend Articles

• Trouble creating an Add-in for Excel wit
• passing commands to VBA in PPT?
• Setting Password Char in InputBox?
• Opening a Word file from a macro in Excel
• VB & VBA - page setup options comple
• Access Project and Views
• .lookin =
• Excel COMBOBOX data sources
• Macros - Excel
• Web services reference not displayed
• SQL within a VBA Module
• calling a function and passing the name
• Automatic BCC from Outlook (VBA)
• Upgrading from Excel 2000 to 2003
• DDE, OLE, Linking, etc.