VBA: Help on run time error 424 - Object required

  • Thread starter Thread starter Frank Krogh
  • Start date Start date
F

Frank Krogh

I have a simplified example of my problem with displaying the DCOUNT
function in a Userform label.

http://www.npr.no/html/dcount_in_userform.xls

As shown, the DCOUNT function works just fine when written in the sheet.

Thanks for any explanation on why I receive this VBA run time error.


Frank Krogh
 
Frank,

You can't just plug a worksheet function into VBA and expect it to work. In
worksheets, you define a range a s A1:A100 or myRange, in VBA it is
Range("A1:A100"), or Range("myRange"), so your code should look like

result = Application.WorksheetFunction.DCount(Range("myDatabase"), "Age",
Range(" myCriteria"))

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 

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

Back
Top