Share via

Why does range formula cause a type mismatch error?

Anonymous
2012-08-19T02:16:09+00:00

I have been working from a text book of VBA for Office 2000 but using Office 2010. When I put the following command in the intermediate window to update the value in the identified range in the VBA editor, I get a type mismatch error. I thought this command worked in Office 2000. Doesn't it work in 2010?

?Worksheets(1).Range("C10:D10").value = 5

Thank you

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2012-08-19T02:42:01+00:00

I found the problem. I was trying to run the command in the intermediate window. When I put it in a sub procedure, it ran fine.

Thanks.

Was this answer helpful?

0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Anonymous
    2012-08-19T23:00:49+00:00

    Try

    ?WorksheetFunction.CountA (Range("C10:D10"))

    This will return the number of non-blank entries in C10:D10.

    To count the number of 5's in the range, use

    ?WorksheetFunction.CountIf(range("C10:D10"),5)

    You can use your code only with a range containing a single cell, not multiple cells.

     Bad:

    ?Worksheets(1).Range("C10:D10").value = 5

    Good

    ?Worksheets(1).Range("C10").value = 5

    Was this answer helpful?

    0 comments No comments
  2. Ashish Mathur 101.9K Reputation points Volunteer Moderator
    2012-08-19T02:28:35+00:00

    Hi,

    Try this if you wish to count filled up cells in C10:D10

    ?Worksheets(1).application.worksheetfunction.counta(Range("C10:D10"))

    Hope this helps.

    Was this answer helpful?

    0 comments No comments