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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:43:06+00:00 2026-05-30T11:43:06+00:00

This macro runs on the click of a button. I receive an error. Run-time

  • 0

This macro runs on the click of a button. I receive an error.

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

I click Debug and it leads me to this highlighted area.

Selection.Find(What:=DateString, After:=ActiveCell, LookIn:=xlFormulas, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False).Activate

Here is the entire function

Function GetBalance(Month As Integer) As Currency
'This function is called by the Calculate_Balance subroutine. It
'finds the appropriate month's balance on an employee sheet and sends
'it back to the calling routine.

Dim DateString As String
Dim RangeString As String
Dim Balance
Dim BalDate As Date
Dim strCurrMonth As String
Dim strCurrYear As String
Dim strFirstDayCurrMonth As String

    strCurrMonth = CStr(DatePart("m", Date))
    strCurrYear = CStr(DatePart("yyyy", Date))
    strFirstDayCurrMonth = strCurrMonth & "/1/" & strCurrYear
    dtmFirstDayCurrMonth = CDate(strFirstDayCurrMonth)

    DateString = Month & "/1/"

    Columns("A:A").Select
    Range("A6").Activate
    Selection.Find(What:=DateString, After:=ActiveCell, LookIn:=xlFormulas, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False).Activate

    CurrRow = ActiveCell.Row
    BalanceRow = CurrRow - 1 'Move up 1 row to get last balance for this month

    RangeStr = "E" & BalanceRow
    DateRangeStr = "A" & BalanceRow

    BalDate = Range(DateRangeStr).Value
    If BalDate <= dtmFirstDayCurrMonth Then
        Balance = Range(RangeStr).Value
    Else
        Balance = 0
    End If

    GetBalance = Balance

End Function
  • 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-30T11:43:08+00:00Added an answer on May 30, 2026 at 11:43 am

    The Find() function returns a Range object so with your code if nothing is found, you will get a error as it can not ‘activate’ nothing. Change the code to something like:

    Dim rng As Range
    
    Set rng = Selection.Find(What:=DateString, After:=ActiveCell, LookIn:=xlFormulas, SearchDirection:=xlNext, MatchCase:=False)
    
    If Not (rng Is Nothing) Then
        rng.Activate
    End If
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, nothing happens when I run this macro. What might I be
Im getting this error when trying to run a program in creating, how shold
In short, I would either: Create a macro that runs every time a cell
This macro should activate tabs in sequence from 1th to 5th and then again.
I have seen this macro defined before but never really knew its purpose. Can
I have found this macro while digging in the source code of tweejump game.
I'm learning SAS and write this macro: %macro firstMacro(mvLO, OLO); %local Count; %local Wordy;
I have an application that used Macro. In this macro I would like to
I want to connect to DB2 from excel macro...This is my code, but it
I've been using the macro from this blog entry for attaching the Visual Studio

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.