+ Reply to Thread
Results 1 to 6 of 6

Thread: Select data within a range and convert to text

  1. #1
    Registered User
    Join Date
    12-13-2011
    Location
    Bristol
    MS-Off Ver
    Excel 2010
    Posts
    4

    Select data within a range and convert to text

    Am very new to VBA and am using it to create a pivot chart in an worksheet. The first thing I have to do is select a range and convert the text within it to number. This is the text I have been using

    
        Range("F1").Select
        Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
        For Each xCell In Selection
        If IsNumeric(xCell.value) Then xCell.value = CDec(xCell.value)
        ActiveWindow.DisplayZeros = False
        
    Next xCell
    This does work but it takes a long time and I was wondering if anyone would be able to advise if there's an easier way!

    Thanks!
    Last edited by bluealex; 12-13-2011 at 08:20 AM.

  2. #2
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    19,226

    Re: Select data within a range and convert to text

    Keeping your approach, this should speed thing up significantly.
    ActiveWindow.DisplayZeros = False
    Application.ScreenUpdating = False
    
    For Each xCell In Range("F1", Range("F1").SpecialCells(xlLastCell))
        If IsNumeric(xCell.Value) Then xCell.Value = CDec(xCell.Value)
    Next xCell
    
    Application.ScreenUpdating = True

    As per forum rules, you should EDIT your post above and add code tags around your code, as I've demonstrated here.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    12-13-2011
    Location
    Bristol
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Select data within a range and convert to text

    Sorry. Am new to this too.

    Am very new to VBA and am using it to create a pivot chart in an worksheet. The first thing I have to do is select a range and convert the text within it to number. This is the text I have been using

    Range("F1").Select
    Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
    For Each xCell In Selection
    If IsNumeric(xCell.value) Then xCell.value = CDec(xCell.value)
    ActiveWindow.DisplayZeros = False
    
    Next xCell
    This does work but it takes a long time and I was wondering if anyone would be able to advise if there's an easier way!

    Thanks!

    Is that right now?
    Last edited by bluealex; 12-13-2011 at 07:58 AM.

  4. #4
    Registered User
    Join Date
    12-13-2011
    Location
    Bristol
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Select data within a range and convert to text

    Sorry and thanks for the code - will try it!

  5. #5
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    19,226

    Re: Select data within a range and convert to text

    No, I didn't want you to add a new (also incorrectly formatted) post, but to EDIT post #1 to add the code tags. See my signature for the correct tags, now you'll need to fix two posts! That's ok, it's good practice for you.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

  6. #6
    Registered User
    Join Date
    12-13-2011
    Location
    Bristol
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Select data within a range and convert to text

    Thanks very much - that worked fabulously! Sorry for all my previous formatting errors! Have read the forum rules properly now

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.2.0