+ Reply to Thread
Results 1 to 17 of 17

VBA convert numbers stored as text

  1. #1
    Registered User
    Join Date
    12-23-2020
    Location
    WY,USA
    MS-Off Ver
    365
    Posts
    36

    VBA convert numbers stored as text

    Hello,

    I will frequently have data that gets exported from an external source download to an excel file. I have created a separate excel file which has the formatting and layout that I want, that I copy and paste the exported data into.

    The issue is that the data from the exported file is stored as text, I need my separate excel file to automatically convert the numbers stored as text in column F into numbers(just like if I selected the cells and hit the error button and click convert to numbers.)

    There will always be some entries which are mixed numbers and letters, but that is ok, I just need to figure out a way to automate the function that occurs when I select all the cells in column F of the table and click "convert to number"

    I have tried a few and a couple of ways were close to working but they either had an error, or made excel start acting funny.

    The only thing I got to work was to automatically change the format of column F cells to number format....but that didnt change the format of the stored text entry.

    Im attaching a sample worksheet incase anyone has any ideas.

    Thanks.
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    935

    Re: VBA convert numbers stored as text

    Have you tried writing 1 (one) in a cell, copy that cell, then select the entire column to format and do a Paste Special... / select operation Multiple / OK.

  3. #3
    Registered User
    Join Date
    12-23-2020
    Location
    WY,USA
    MS-Off Ver
    365
    Posts
    36

    Re: VBA convert numbers stored as text

    Quote Originally Posted by rollis13 View Post
    Have you tried writing 1 (one) in a cell, copy that cell, then select the entire column to format and do a Paste Special... / select operation Multiple / OK.
    Hmm when I do that it "adds rows to the table" and shifts my formulas and throws it off. It also gets rid of the conditional formatting I have in the file that im pasting into...which I now realize I didnt include in my sample work book.

    My apologies.

  4. #4
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    935

    Re: VBA convert numbers stored as text

    Didn't find any formulas in your data !

    You can also try:
    1) press F5, select Table13 and click OK
    2) then from menu Data choose Text to Columns (all default options are ok) and click End
    Last edited by rollis13; 02-11-2021 at 06:14 PM.

  5. #5
    Valued Forum Contributor
    Join Date
    11-26-2012
    Location
    Sydney
    MS-Off Ver
    2010
    Posts
    423

    Re: VBA convert numbers stored as text

    Try setting the range equal to itself, e.g. something like
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    12-23-2020
    Location
    WY,USA
    MS-Off Ver
    365
    Posts
    36

    Re: VBA convert numbers stored as text

    Quote Originally Posted by rollis13 View Post
    Didn't find any formulas in your data !

    You can also try:
    1) press F5, select Table13 and click OK
    2) then from menu Data choose Text to Columns (all default options are ok) and click End
    I know, my bad. I updated the file to reflect what im working with more. I cant show all the data in the table because reasons, but column F is the one with the issue. Formulas are located in column N.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    12-23-2020
    Location
    WY,USA
    MS-Off Ver
    365
    Posts
    36

    Re: VBA convert numbers stored as text

    Quote Originally Posted by mgs73 View Post
    Try setting the range equal to itself, e.g. something like
    Please Login or Register  to view this content.
    This is really close. It seems to work but it has some weird side effects.

    This is what I put in VBA (based upon the latest sample workbook I just uploaded in the response to rollis)

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    It seems to do what I asked, but it also makes excel glitchy(I think?) When I select a cell and am actively typing it shows up in a completely random cell for no apparent reason, but when I hit enter it does go to the proper cell.

    Also, when I go to test the entries in column F with ISNUMBER or ISTEXT, it returns a zero rather than TRUE or FALSE.

    Any idea why its doing those other things?

  8. #8
    Registered User
    Join Date
    12-23-2020
    Location
    WY,USA
    MS-Off Ver
    365
    Posts
    36

    Re: VBA convert numbers stored as text

    This seems to work, except if I clear the data in the table...then it gets an error an crashes.

    Formula: copy to clipboard
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    12-23-2020
    Location
    WY,USA
    MS-Off Ver
    365
    Posts
    36

    Re: VBA convert numbers stored as text

    This worked, and adding the specified row numbers instead of the entire row got rid of the errors.

    Thanks for the insight, Rollis your suggestion of Text to Columns put me on the right track, Thanks!


    Formula: copy to clipboard
    Please Login or Register  to view this content.

  10. #10
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    935

    Re: VBA convert numbers stored as text

    But how many times must this formatting need to be done ? Can't it be done manually once every now and then, the goal is only four clicks away.

    A macro with event Worksheet_Change triggering will execute at every cell change every few istants.
    Anyway, what difference would this macro make:
    Please Login or Register  to view this content.
    Last edited by rollis13; 02-13-2021 at 03:44 AM.

  11. #11
    Registered User
    Join Date
    12-23-2020
    Location
    WY,USA
    MS-Off Ver
    365
    Posts
    36
    Quote Originally Posted by rollis13 View Post
    But how many times must this formatting need to be done ? Can't it be done manually once every now and then, the goal is only four clicks away.

    A macro with event triggering will execute at every cell change every few istants.
    Anyway, what difference would this macro make:
    Please Login or Register  to view this content.

    The thing is, the file I'm working on is a tool that will need to be used by about 50 other people, most of which would rather reconcile by hand rather than learn those 4 clicks, so it needs to be as automated as possible.

    Once every 2 weeks or so they will generate a report of new data, unique to the current time period, and paste into a blank table, therefore all the data they paste into the table will need to be converted.

    After pasting the data, they will utilize filters and sorts to organize the data to the order that works for their location.

    I will give your new macro a shot tomorrow to see how it behaves, definitely looks cleaner than what I have currently.

  12. #12
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    935

    Re: VBA convert numbers stored as text

    Well, instead of having the macro triggering hundreds of time a day (wasting energy) you could use event Worksheet_Activate that will trigger only when you select (activate) that specific sheet (or maybe never if you never move from one sheet to another).

  13. #13
    Registered User
    Join Date
    12-23-2020
    Location
    WY,USA
    MS-Off Ver
    365
    Posts
    36

    Re: VBA convert numbers stored as text

    I see what you are saying....and when looking into it it helped me understand why CTRL+Z wasn't working for this sheet....its because that Macro was running all the time. I get it.

    Here is what I updated it to, I have a command button that pastes as values in the proper cell, so they have to push that to paste the data into the table, and I just tossed the command in with that so it only runs the one time when they put the data into the table.

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    I am trying yours too, but it doesnt seem to do anything.

    Formula: copy to clipboard
    Please Login or Register  to view this content.

  14. #14
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    935

    Re: VBA convert numbers stored as text

    It looks like you are pasting in column A but you have target column G in the first macro and column F in the other; which is the right column ?
    Last edited by rollis13; 02-13-2021 at 12:48 PM.

  15. #15
    Registered User
    Join Date
    12-23-2020
    Location
    WY,USA
    MS-Off Ver
    365
    Posts
    36

    Re: VBA convert numbers stored as text

    Quote Originally Posted by rollis13 View Post
    It looks like you are pasting in column A but you have target column G in the first macro and column F in the other; which is the right column ?
    Correct, sorry I forgot that I have added a new column since yesterday. Column F became column G.

    Column G is where the data is that needs converting.

    A5 is the top left corner of the table where the data values need to be pasted.

  16. #16
    Registered User
    Join Date
    12-23-2020
    Location
    WY,USA
    MS-Off Ver
    365
    Posts
    36

    Re: VBA convert numbers stored as text

    Quote Originally Posted by rollis13 View Post
    It looks like you are pasting in column A but you have target column G in the first macro and column F in the other; which is the right column ?
    I working a bunch more bugs than just this one at the same time....my sincerest apologies for my brain fart when I tested your formula, while I did update the column on mine, I forgot to do it on yours.

    Took a me a minute to see it, I just got too many windows and modules open at the same time lol.

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    This does work beautifully.

    Thanks again for the help.

  17. #17
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    935

    Re: VBA convert numbers stored as text

    Glad having been of some help .

+ 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. VBA to convert a range from numbers to numbers stored as text (Text to Columns)
    By tantcu in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-06-2017, 05:50 PM
  2. [SOLVED] Marco to convert numbers stored as text to numbers and dates stored as text to numbers
    By a2424 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-22-2014, 10:19 AM
  3. [SOLVED] Convert numbers stored as text to numbers for range of data that changes
    By excel2425 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-06-2014, 01:57 PM
  4. [SOLVED] Convert all numbers stored as text or custom formatted to numbers &no decimals - 40 sheets
    By synses in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-19-2013, 01:46 AM
  5. [SOLVED] How do you apply the int() in VBA in order to convert numbers stored as text to numbers
    By djaurit in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-21-2012, 02:57 PM
  6. Replies: 2
    Last Post: 10-22-2009, 02:50 PM
  7. [SOLVED] Convert numbers stored as text to numbers Excel 2000
    By Darlene in forum Excel General
    Replies: 6
    Last Post: 01-31-2006, 04:10 PM

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