Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6214377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:51:56+00:00 2026-05-24T06:51:56+00:00

I have a problem that I don’t understand at all: i = 150 If

  • 0

I have a problem that I don’t understand at all:

i = 150
If ActiveWorkbook.Worksheets("foobar").Cells(i, 3).Value Like "*:*" Then
  MsgBox "I found a colon!"
End If

As you might guess, the sheet foobar has at position (150, 3) a cell containing a colon, thus the message box is shown.

Now I want to do this:

i = 150
Cell = ActiveWorkbook.Worksheets("foobar").Cells(i, 3).Value 'fails right here
If Cell Like "*:*" Then
  MsgBox "I found a colon!"
End If

Here it gives me an error saying “Object variable or With block variable not set. In fact saying:

Sheet = ActiveWorkbook.Worksheets("foobar")

gives a similar message. Why? What am I doing wrong? I just want a reference of that object, or at least a refence.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T06:51:57+00:00Added an answer on May 24, 2026 at 6:51 am

    Bottomline:

    • When handling objects, use Set.
    • When handling primitive data (integers, longs, strings*, variants*) you do not use it.

    Sheet, Workbook, Range, are objects. Therefore, you need to use Set when assigning them to variables.

    A Range.Value returns a Variant (that can be a long, a string, etc.) So, you cannot use Set.

    ==========================

    Now, about your error message… I’d say then that maybe before in your code, Cell is being declared as object. Try use another variable name, or check the Cell variable type.

    To check this, right click on it and then click in ‘Definition’. Have it declared as Variant might fix the problem (be aware of side effects it might cause, though).

    ==========================

    *I know these types aren’t ‘primitive’; I used as an example here for the sake of explanation’s cleanliness.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a strange problem that I don't understand about DataPager. After changing the
I have a little problem that I don't understand. I have a db that
I have a weird problem that I don't fully understand how to solve. Could
So I have a problem that I don't really know how to go about.
i have a problem, that i don't know how to solve it. i have
One problem that I come across regularly and yet don't have a solution to
I have a problem drawing something quickly in .NET. I don't think that any
So, one problem pattern that I keep coming across and don't have a good
I have a problem that I would like have solved via a SQL query.
I have a problem that I don't know how to solve. I have have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.