Problem moving code from module to form

Kylep

Registered User.
Local time
Yesterday, 23:29
Joined
Jun 29, 2004
Messages
12
I'm running some code to open up an excel book and clean it up before importing into access. This code works fine in a module, but is giving me some problems when I try to put it in the form and attach it to the button. I'm getting "The expression you entered contains invalid syntax" with possible reason's including an error evaluating a function, which is what I think is happening. I'm pretty sure the problem is with the following code:
Code:
    'finds the last row in the book to determine how many times to run loop.
dim lastrow as long
    If WorksheetFunction.CountA(Cells) > 0 Then
        lastrow = Cells.Find(what:="*", after:=[A1], _
            searchorder:=xlByRows, _
            SearchDirection:=xlPrevious).Row
    End If

This exact same code works fine in the module. Any ideas?

This
 
Why put it in the form? Just declare it as public and call it from your button.
 
Honestly, I guess I don't know why. It seems like from what I've read on this forum that putting code into a form is a preferred method, I believe for error-catching.
 

Users who are viewing this thread

Back
Top Bottom