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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:48:55+00:00 2026-05-23T10:48:55+00:00

I’m confused as to why the following code works in one instance, then fails

  • 0

I’m confused as to why the following code works in one instance, then fails in another. The following gives a #VALUE! error.

Function RateFetcher(Plan_Text As String, Zip_Text As String, Sex As String, Tabacco_Use As String, Age As Integer, State As String)

Dim Plan As String
Plan = StrConv("Plan " + Plan_Text, vbLowerCase)

Dim ProperState As String
ProperState = StrConv(State, vbProperCase)

Dim Search_Range As Range
Search_Range = Worksheets(ProperState).Range("A4:A600")
MsgBox (Search_Range)

Dim Location As String

For Each c In Search_Range
    If StrConv(c.Value, vbLowerCase) = Plan And c.Offset(1, 0) = Zip_Text Then
        Location = c.Address
    End If
Next c

Dim Sex_Tab_Offset As Integer

Dim Combined As String

Combined = Sex + Tabacco_Use

If Combined = "F NO" Then
    Sex_Tab_Offset = 1
ElseIf Combined = "M NO" Then
    Sex_Tab_Offset = 2
ElseIf Combined = "F YES" Then
    Sex_Tab_Offset = 3
Else
    Sex_Tab_Offset = 4
End If

Dim Age_Offset As Integer
Age_Offset = Age - 65

RateFetcher = Worksheets(ProperState).Range(Location).Offset(Age_Offset, Sex_Tab_Offset).Value
End Function

Whereas, this works. The difference is that I’m explicitlty defining the Search_Range, but I’d like to have the flexibility of the first example because then I won’t have to define each range to search. The range to search is State_name!$A$4:$A$500.

`

 Function RateFetcher(Search_Range As Range, Plan_Text As String, Zip_Text As String, Sex As String, Tabacco_Use As String, Age As Integer, State As String)

Dim Plan As String
Plan = StrConv("Plan " + Plan_Text, vbLowerCase)

Dim ProperState As String
ProperState = StrConv(State, vbProperCase)

'Dim Search_Range As Range
'Search_Range = Worksheets(ProperState).Range("A4:A600")

Dim Location As String

For Each c In Search_Range
    If StrConv(c.Value, vbLowerCase) = Plan And c.Offset(1, 0) = Zip_Text Then
        Location = c.Address
    End If
Next c

Dim Sex_Tab_Offset As Integer

Dim Combined As String

Combined = Sex + Tabacco_Use

If Combined = "F NO" Then
    Sex_Tab_Offset = 1
ElseIf Combined = "M NO" Then
    Sex_Tab_Offset = 2
ElseIf Combined = "F YES" Then
    Sex_Tab_Offset = 3
Else
    Sex_Tab_Offset = 4
End If

Dim Age_Offset As Integer
Age_Offset = Age - 65

RateFetcher = Worksheets(ProperState).Range(Location).Offset(Age_Offset, Sex_Tab_Offset).Value

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-23T10:48:55+00:00Added an answer on May 23, 2026 at 10:48 am

    You want to Set the reference to Range because Range is an object:

    Dim Search_Range As Range
    Set Search_Range = Worksheets(ProperState).Range("A4:A600")
    

    Also, MsgBox expects an argument of type String, so you can’t MsgBox a Range like that. You have to say what property of the Range you want to display, and I’m guessing you want to display its address:

    MsgBox Search_Range.Address
    

    Aa an aside, the default property of Range is Value, so MsgBox Search_Range would have worked if Search_Range were a reference to a single cell… but in your case, Search_Range.Value returns a 597-element Variantarray, and this can’t be implicitly coerced to a String.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I need a function that will clean a strings' special characters. I do NOT
I want to construct a data frame in an Rcpp function, but when I

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.