+ Reply to Thread
Results 1 to 9 of 9

Macro Variable Code

  1. #1
    Forum Contributor
    Join Date
    09-30-2010
    Location
    Minnesota, USA
    MS-Off Ver
    Excel 2010
    Posts
    109

    Macro Variable Code

    Is there a macro variable code that will allow the variable to look at Text and read it like a number?
    I have numbers that are placed in my spread sheet as Text, and I need to get an Average of a small group of them. I have tried converting them to numbers, but that causes errors for other macros.


    Please Login or Register  to view this content.
    Last edited by CityMPLSEmpolyee; 10-01-2010 at 03:56 PM.

  2. #2
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Macro Varible Code

    You can convert them in the code using the CLng, CInt, CDbl, and CSng functions. For more info see the Type Conversion Functions in the VBA help.

    Assuming one of your numbers written as text is in cell A1, it'd look like this:

    Please Login or Register  to view this content.
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  3. #3
    Forum Contributor
    Join Date
    09-30-2010
    Location
    Minnesota, USA
    MS-Off Ver
    Excel 2010
    Posts
    109

    Re: Macro Varible Code

    Thank you
    I'll try this

  4. #4
    Forum Contributor
    Join Date
    09-30-2010
    Location
    Minnesota, USA
    MS-Off Ver
    Excel 2010
    Posts
    109

    Re: Macro Varible Code

    this is what I have
    Please Login or Register  to view this content.
    Last edited by shg; 10-01-2010 at 04:03 PM. Reason: fix code tags

  5. #5
    Forum Contributor
    Join Date
    09-30-2010
    Location
    Minnesota, USA
    MS-Off Ver
    Excel 2010
    Posts
    109

    Re: Macro Varible Code

    The numbers that I am trying to work with are pasted in and they have spaces included with them from the original source.

  6. #6
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Macro Varible Code

    I ran your code above on some cells with numbers formatted as text and it worked as expected. If it is not working for you could you post a sample worksheet with some numbers that you are not able to average?

  7. #7
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Macro Varible Code

    Try this instead:

    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    09-30-2010
    Location
    Minnesota, USA
    MS-Off Ver
    Excel 2010
    Posts
    109

    Re: Macro Varible Code

    How do I post a sample

  9. #9
    Forum Contributor
    Join Date
    09-30-2010
    Location
    Minnesota, USA
    MS-Off Ver
    Excel 2010
    Posts
    109

    Re: Macro Variable Code

    excellent it worked perfect.
    thank you

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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