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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:15:39+00:00 2026-06-12T09:15:39+00:00

Consider the following VBA function: Function getFirstColumn(Optional sheetName As String) As Long ‘In particular

  • 0

Consider the following VBA function:

Function getFirstColumn(Optional sheetName As String) As Long
    'In particular the IF statement below.
    If sheetName = "" Or sheetName = Null Then sheetName = ActiveWorkbook.ActiveSheet.Name
    With ActiveWorkbook.Worksheets(sheetName)
        getFirstColumn = .Cells.Find("*", .Cells(1), xlFormulas, xlWhole, xlByColumns, xlNext).Column
        If Err <> 0 Then getFirstColumn = 0
    End With
End Function

When using this function, I don’t have problems when using it from a second opened sheet.

But when the code is changed to it’s function-based equivalent, 'If IsEmpty(sheetName) Or IsNull(sheetName) Then sheetName = ActiveWorkbook.ActiveSheet.Name, I get problems if I try to use the function from a sheet that doesn’t own it:

Erro em tempo de execução ‘9’:
Subscrito fora do intervalo.

What are the differences between them? And why is such error triggered exactly?

  • 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-12T09:15:40+00:00Added an answer on June 12, 2026 at 9:15 am

    “sheetName” is a variable. The variable may be undefined, might refer to an object … or might be NULL.

    If it’s an object, the object itself might evaluate to the variant value NULL. Hence the “IsNull()” function.

    Other variants include “IsEmpty()” (which you mentioned), “IsNothing()” and even “IsMissing()”:

    • http://social.msdn.microsoft.com/Forums/en-US/accessdev/thread/aff30d44-0a7d-435e-8f15-7edd4f7f03d1/

    • http://www.tek-tips.com/faqs.cfm?fid=3710

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

Sidebar

Related Questions

Consider following string Some string with quotes and \pre-slashed\ quotes Using regex, I want
Consider following program: static void Main (string[] args) { int i; uint ui; i
Consider following code for an android app; private String GetDistance(String src, String dest) {
Please consider following schema CREATE table articles ( id Int UNSIGNED NOT NULL AUTO_INCREMENT,
Consider following JavaScript code (tested in Firefox): function f(a) { if (a == undefined)
Consider following code: ArrayList<Integer> aList = new ArrayList<Integer>(); aList.add(2134); aList.add(3423); aList.add(4234); aList.add(343); String tmpString
Consider following example. #include <iostream> #include <boost/optional.hpp> template < typename A > int boo(
Consider following situation: there is ComboBox and a filter TextBox, then user types a
Consider following statement: C a, b; //C contains c1, c2 and c3 all integers
Consider following function definition in ghci. let myF = sin . cos . sum

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.