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

  • Home
  • SEARCH
  • 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 8108275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:03:40+00:00 2026-06-06T01:03:40+00:00

I just solved a problem I was having putting the Set keyword in a

  • 0

I just solved a problem I was having putting the “Set” keyword in a definition line but what I would like to know is “why” ?

Basically, I am doing this:

Dim startCell, iCell as Range
For Each iCell in Range(whatever)
    If iCell.value <>"" Then
        Set startCell = Cells(iCell.Row + 1, iCell.Column)
    End If
Next iCell

If I omit the “Set” keyword the code still compiles fine, but in the local variables window I see that its type changes to “String” instead of “Variant/Object/Range”. Why would that happen ?

  • 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-06-06T01:03:41+00:00Added an answer on June 6, 2026 at 1:03 am

    This is why. When you say this:

    Dim startCell, iCell As Range
    

    you think you’ve done this:

    Dim startCell As Range, iCell As Range
    

    but what you’ve really done is this:

    Dim startCell 'As Variant, by default
    Dim iCell As Range
    

    This is a classic VBA mistake. Most VBA programmers have made it, and that’s why most VBA programmers fall back on declaring only one variable per Dim statement (i.e. one per line). Otherwise it’s way too easy to make that mistake, and difficult to spot it afterwards.

    So with Dim startCell you’ve implicitly declared your variable as Variant type (equivalent to Dim startCell As Variant).

    When you then say this:

    Set startCell = Cells(iCell.Row + 1, iCell.Column)
    

    the Variant acquires the type of the thing on the right hand side of the reference assignment (Range). However, when you say this:

    startCell = Cells(iCell.Row + 1, iCell.Column)
    

    without the Set keyword, you’re not assigning a reference, but a value to the variable startCell, which now acquires the type of the value on the right hand side. What is that type? Well, the default property of a Range object is Value, so you’re going to get the type of Cells(iCell.Row + 1, iCell.Column).Value. If that cell contains a string, then you’ll get a string.

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

Sidebar

Related Questions

This is not really a question because I just solved the problem, but I
I have solved this problem, I just need to know what to do. I
I just solved the first problem from Project Euler in JavaFX for the fun
I have a problem and I just do not know how to solve it.
I've got a problem and I just don't know how to solve this (relatively)
I'm just starting with jQuery, and having trouble doing something embarrassingly simple: using .load()
After having solved the problem of getting the editor to launch when there's a
I am having problem with my PHP coding lately. I used to code like
I'm having a problem with pointers. Basically I have a struct which works as
I'm having some trouble with what I thought would be a simple problem. I'd

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.