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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:56:24+00:00 2026-06-09T13:56:24+00:00

I receiving a strange error when running this subroutine in VBA: Sub NameColumns() ‘

  • 0

I receiving a strange error when running this subroutine in VBA:

Sub NameColumns()
' name key columns for later reference in formulas
Dim startdatecol As Integer

' name start date column
startdatecol = ActiveSheet.Cells.Find(What:="Start Date", after:=[a1], LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Column
End Sub

Run time error ’91’: Object variable or With variable not set

Any ideas on how I can fix this subroutine error? And why it is occurring?

Thanks,
AME

  • 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-09T13:56:25+00:00Added an answer on June 9, 2026 at 1:56 pm

    The problem is that Find is not finding the cell.

    You will find (pun intended) that the following is true:

    MsgBox ActiveSheet.Cells.Find(What:="Start Date", after:=[a1], LookIn:=xlValues, _
    LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=False) Is Nothing
    

    The first thing you should do is fix your search so that it finds the cell you’re looking for.

    Edit:

    Maybe a change that would better illustrate the problem is this:

    Dim found as Range
    Dim startDateCol as Integer
    
    Set found = ActiveSheet.Cells.Find(What:="Start Date", after:=[a1], LookIn:=xlValues, _
    LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=False)
    
    If Not found Is Nothing Then startDateCol = found.Column
    
    MsgBox startDateCol 'This will be zero if the "Start Date" cell wasn't found.
    

    Edit to respond to comment:

    'This should find the exact text "Start Date" (case sensitive) in the header row.
    'A cell containing, for example "The Start Date" will not be matched.
    Set found = ActiveSheet.Range("1:1").Find("Start Date", LookIn:=xlValues, _
                                               LookAt:=xlWhole, MatchCase:=True)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm receiving a strange error from my call to query() the database. This normally
some weeks from now I've been receiving this strange message almost every time I
I receiving a undefined reference error when try to compile an c++ program. I'm
I keep receiving this error... [2012-06-14 11:54:50,072: ERROR/MainProcess] Hard time limit (300s) exceeded for
I am receiving a parse error which is this: Parse error: syntax error, unexpected
Why am I receiving this Rake error: $ rake --version /Volumes/Data/sampablokuper/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not
Error I'm receiving Invalid argument supplied for foreach() The offending portions is this: foreach($subs[$id]
I am using VBA for Excel 2010 and randomly receiving the following error: Run-time
This is very strange. My view is receiving a notification with an index number
Receiving this error (JSON.parse: unexpected character) when I try to parse a JSON validated

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.