+ Reply to Thread
Results 1 to 5 of 5

Explanation of use of the character " # "

  1. #1
    Registered User
    Join Date
    12-10-2019
    Location
    Estero, FL
    MS-Off Ver
    2019
    Posts
    3

    Explanation of use of the character " # "

    Can someone tell me what the function is for the " # " sign at the end of a number - such as in:

    Const dia As Double = 150#
    Const ctrX As Double = 200#
    Const ctrY As Double = 100#

    Could not find anything on the web other than as an ASCII character definition.

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: Explanation of use of the character " # "

    Hey DouCow,

    Look on https://excelmacromastery.com/vba-dim/ down in the Replies.
    "There are only a few possible suffixes" for Dim Type
    # = Double, % = Integer, & = Long, ! = Single, $ = String

    Some VBA code writers like to use
    Please Login or Register  to view this content.
    instead of
    Please Login or Register  to view this content.
    I hate this type of short Dim statement as it makes me stop and look up what the #%$& stuff means. Learn to write better VBA and make your variables meaningful. Instead of i, j, k; name them LastRow, RowCtr, ColCtr. That way reading the code is much easier.

    While I'm on this rant....
    We have a few Gurus on this site who want to write as few lines of code as possible. I've struggled understanding their code just because they don't Dim their variables with real words. Then when I ask WTF their code is doing they say it works and that is enough. If we are here to help explain answers to problems, I'd like to see readable VBA code. End Rant
    Last edited by MarvinP; 03-22-2020 at 12:34 PM.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: Explanation of use of the character " # "

    Now that I'm over my rant... I think the "#" at the end of the lines doesn't make sense. I wonder if it works?
    Read: https://docs.microsoft.com/en-us/dot...are-a-constant

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: Explanation of use of the character " # "

    I also see a method to see which type of Dim declaration wins. With something like:
    Please Login or Register  to view this content.
    Will bob be a double or single (!)?
    This line of code will show which type bob really is:
    Please Login or Register  to view this content.
    which returns a "DOUBLE"
    Read this site:
    http://www.learnexcelmacro.com/wp/20...in-a-variable/

  5. #5
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,414

    Re: Explanation of use of the character " # "

    Quote Originally Posted by MarvinP View Post
    I think the "#" at the end of the lines doesn't make sense. I wonder if it works?
    It will work, but it won't matter for whole numbers if you include it or not (actually, in most cases it will not matter, but you do have to be careful). What that symbol does is convert the number to the data type indicated by the symbol before making the assignment. Here is an example where it would matter...

    Const X As Double = 12.123456!
    MsgBox.Print X

    The VBA processor will change the 12.123456! to 12.12346! in order to make it fit into a Single data type (you are seeing the rounded value for a Single data type, but there are some "guard digits" that are unseen to help keep calculations somewhat "exact"). If you run the code, the MessageBox will display 12.1234560012817 instead of the 123456 that was originally intended because that is what that Single value becomes when promoted to a Double.
    Last edited by Rick Rothstein; 03-22-2020 at 01:20 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Explanation of MMULTI and "256" and REPT func in formula for multiple criteria problem
    By JulianS96 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-04-2020, 04:17 AM
  2. Replies: 4
    Last Post: 09-10-2017, 03:03 AM
  3. Replies: 1
    Last Post: 08-10-2014, 01:22 PM
  4. [SOLVED] how to replace the "Alt-Enter" character in a cell with sway "@"
    By jmac1947 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-04-2014, 05:55 AM
  5. [SOLVED] Merged cells autofit and "-"/"+" is first character
    By Linky in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 04-21-2013, 11:27 AM
  6. [SOLVED] remove all characters to right of "-" character, including "-"
    By maacmaac in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-27-2012, 02:43 PM
  7. [SOLVED] Explanation for Excel message "no more fonts may be applied"?
    By Ralph Coomber in forum Excel General
    Replies: 2
    Last Post: 05-05-2005, 08:06 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1