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 8512871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:23:58+00:00 2026-06-11T04:23:58+00:00

I only use VBA occasionally, and every time I come back to it I

  • 0

I only use VBA occasionally, and every time I come back to it I get caught out by some variation of the following:

I have a Range object, currentCell, that I use to keep track of what cell I’m working with in the spreadsheet. When I update this to point to a different cell, I write:

currentCell = currentCell.Offset(ColumnOffset:=1)

The problem is that I’ve forgotten the Set keyword, so what the above line actually does is use the default property of the Range objects:

currentCell.Value = currentCell.Offset(ColumnOffset:=1).Value

So the contents of the current cell are overwritten by what’s in the new cell, and my currentCell variable hasn’t changed to point to a new cell, and I get filled with rage as I realize I’ve made the same mistake for the hundredth time.

There probably isn’t a better answer than to put a post-it on my monitor saying “Have you remembered to use Set today?”, but if anyone has any suggestions to help me, I’d appreciate hearing them. In particular:

  • Is there any way to turn on warnings when you implicitly use default properties? I have never used them like this on purpose, I’d always call Range.Value if that’s what I meant.
  • Is there any good practice for marking variables as “this should only be used to read from the spreadsheet”? In most code I write, almost all my variables are for gathering data, and it would be handy to get a warning if something starts inadvertently editing cells like this.
  • 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-11T04:24:00+00:00Added an answer on June 11, 2026 at 4:24 am

    Is there any way to turn on warnings when you implicitly use default properties?

    No.

    Is there any good practice for marking variables as “this should only be used to read from the spreadsheet”?

    Well, you could make your own variable naming convention, à la Making Wrong Code Look Wrong, but you’ll still have to check your own code visually and the compiler won’t help you do that. So I wouldn’t rely on this too much.

    A better option is to circumvent the need for repeatedly redifining currentCell using .Offset altogether.

    Instead, read the entire range of interest to a Variant array, do your work on that array, and then slap it back onto the sheet when you’re done modifying it.

    Dim i As Long
    Dim j As Long
    Dim v As Variant
    Dim r As Range
    
    Set r = Range("A1:D5") 'or whatever
    
    v = r.Value 'pull from sheet
    
    For i = 1 To UBound(v, 1)
        For j = 1 To UBound(v, 2)
            'code to modify or utilise element v(i,j) goes here
        Next j
    Next i
    
    r.Value = v 'slap v back onto sheet (if you modified it)
    

    Voilà. No use of default properties or anything that could be confused as such. As a bonus, this will speed up your code execution.

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

Sidebar

Related Questions

I edited the app.py file to only use MongoDB through MongoEngine(you get to choose
I have a cocos2d powered game that uses UIKit menues, so I only use
I have not had much experience with VBA, but I sometimes use it at
Occasionally, I have had to build a SQL string in VBA and execute it
I deal with vendors all the time who seem to only have the capability
How can I use VBA to get the names of all the worksheets (or
In some VBA attached to an Excel 2003 spreadsheet I need to make use
Can i only use HTTP handlers or HTTP modules if i use my ASP.NET
Should we only use Web-Safe Colors while in design/coding/development for website/apps?
Does Git only use the remote name origin for a repository which was created

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.