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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:47:07+00:00 2026-06-10T20:47:07+00:00

Hi All in new to using VBA in excel and was trying to create

  • 0

Hi All in new to using VBA in excel and was trying to create a function that would look at a number and return it as a six digit number.

The function I wrote to try and accomplish this is below but when I use the command =Res(A1) in a cell I just get a #VALUE! as the answer.

The value in cell one at the moment is 30508.

Any help anyone could offer to resolve this would be greatly appreciated. Thanks Guys.

Function Res(myval As Integer) As Integer

Res = 0

If ((myval > 0) And (myval < 10)) Then    
    Res = myval * 100000

ElseIf ((myval > 9) And (myval < 100)) Then
    Res = myval * 10000

ElseIf ((myval > 99) And (myval < 1000)) Then 
    Res = myval * 1000

ElseIf ((myval > 999) And (myval < 10000)) Then  
    Res = myval * 100

ElseIf ((myval > 9999) And (myval < 100000)) Then
    Res = myval * 10

ElseIf ((myval > 999999) And (myval < 10000000)) Then
    Res = myval / 10

Else
    Res = myval

End If

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-06-10T20:47:09+00:00Added an answer on June 10, 2026 at 8:47 pm

    Change Function Res(myval As Integer) As Integer to:

    Function Res(myval As Long) As Long
    

    You’re hitting the integer maximum.

    Long stands for long integer, and you want to use it anytime your number could go above 30k.

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

Sidebar

Related Questions

I am trying to create a new instance of Excel using VBA using: Set
Using VBA i have a set of functions that return an ADODB.Recordset where all
I am trying to write a VBA script which imports all of the Excel
Hope you are well. I'm trying to create a mass folder creator using Excel
I'm pretty new to using MVC3 so hopefully the terms I'm using are all
I've been using ShowDialog() in following way for all my new Windows. SomeGui test
Being resonably new to using GTK+, im not fully aware of all its functionality.
I m new to using Web services using JavaScript. All I want is to
I'm using : PathMatchingResourcePatternResolver rr = new ...; rr.getResources(classpath*:**/*.class) to get all the classes
i am using web service asmx, whenever a new request comes, all objects will

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.