Code that works in Excel but not Access

  • Thread starter BTU_needs_assistance_43
  • Start date
B

BTU_needs_assistance_43

I can use this code to find certain values in Excel but it won't carry over
to Access. Can I tweak this code to make it work in Access or am I at a dead
end with this code?

I posted this in a module:

Option Compare Database

Function Find_Range(Find_Item As Variant, _
Search_Range As Range, _
Optional LookIn As Variant, _
Optional LookAt As Variant, _
Optional MatchCase As Boolean) As Range

Dim c As Range
If IsMissing(LookIn) Then LookIn = xlValues 'xlFormulas
If IsMissing(LookAt) Then LookAt = xlPart 'xlWhole
If IsMissing(MatchCase) Then MatchCase = False

With Search_Range
Set c = .Find( _
What:=Find_Item, _
LookIn:=LookIn, _
LookAt:=LookAt, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=MatchCase, _
SearchFormat:=False)
If Not c Is Nothing Then
Set Find_Range = c
firstAddress = c.Address
Do
Set Find_Range = Union(Find_Range, c)
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With

End Function
-------------------------------------------------------------
Then this as part of a command for a button

Find_Range("Shot Date", Cells, xlFormulas, xlWhole).Cells.Select
Set ShotName = ActiveCell.Offset(2, -1)

Set xlc = xls.Range("ShotName")
..
..
..
and then wrote the values to a table.

When I try to run this code i get an error message that says "Compile error:
User-defined type not defined" and it then highlights the first 5 lines of my
module code.
If I put the code in its own section at the bottom of the vba sheet as its
own section I get another error message that says "The expression On Click
you entered as the event property setting produced the following error:
User-defined type not defined."
 
R

ryguy7272

In Excel this code is dealing with ranges, unions, and cell addresses.
AFAIK, none of these are available in Access. Excel and Access are two
completely different applications. If the code works fine in Excel, what do
you need to transport it to Access for; run it in Excel.

You will have to learn VBA if you want to do anything meaningful with code.

Take a look at this
http://www.amazon.com/Excel-2003-Po...=sr_1_6?ie=UTF8&s=books&qid=1248375530&sr=8-6

Or this, if you use 2007
http://www.amazon.com/Excel-Power-P...=sr_1_2?ie=UTF8&s=books&qid=1248375530&sr=8-2


And For Access
http://www.amazon.com/Access-2003-P...=sr_1_7?ie=UTF8&s=books&qid=1248375658&sr=8-7

And for Access 2007
http://www.amazon.com/Access-2007-P...=sr_1_2?ie=UTF8&s=books&qid=1248375658&sr=8-2

Good luck,
Ryan--
 

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

Top