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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:40:41+00:00 2026-05-20T17:40:41+00:00

I want to have my own function, that is able to search the same

  • 0

I want to have my own function, that is able to search the same area on several worksheets. My idea was to go through a set of sheets (here all sheets in the workbook) and use Find to search that area. Now if the search was successful on the first sheet, I don’t want the result to be overwritten from the unsuccessful searches on the following, there for the if condition.

Function SheetsFind(LookUpValue As Integer) As Variant
    Dim SearchRange As Range

    For Each WS In Sheets
        Set SearchRange = WS.Range("A1:B6")

        If (SearchRange.Find(LookUpValue, LookIn:=xlValues, LookAt:=xlWhole) <> "Nothing") Then
            SheetsFind = SearchRange.Find(LookUpValue, LookIn:=xlValues, LookAt:=xlWhole).Offset(0, 1).Value
        End If
    Next WS

End Function

The problem now is, if the find in the condition is unsuccessful, the function is left and I get a #value error.

Why does my function not just continue with the the next iteration?

  • 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-20T17:40:42+00:00Added an answer on May 20, 2026 at 5:40 pm

    Range.Find returns another range object, for this reason you’re getting problems.

    Try this:

    Function SheetsFind(LookUpValue As Integer) As Variant
    
        Dim SearchRange As Range
        Dim oResult As Excel.Range
        Dim ws As Worksheet
    
        For Each ws In Sheets
            Set SearchRange = ws.Range("A1:B6")
    
            Set oResult = SearchRange.Find(LookUpValue, LookIn:=xlValues, LookAt:=xlWhole)
    
            If Not oResult Is Nothing Then
    
                SheetsFind = oResult.Offset(0, 1).Value
    
            End If
    
        Next ws
    
    End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to have a function that will return the reverse of a list
I want to have a select-only ComboBox that provides a list of items for
I want to have a text box that the user can type in that
I want to have two items on the same line using float: left for
I want to have an executable file that will call some other programs. The
I want to have a map that has a homogeneous key type but heterogeneous
I want to have a PHP script send a XML formatted string to another
I want to have a class which implements an interface, which specifies the specific
I want to have a web based admin to upload, delete files and folders
I want to have the context menu of links provide me an option to

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.