Solved

Select Range and Convert Text to Numbers in Excel VBA

Posted on 2013-01-22
2
372 Views
Last Modified: 2013-01-23
1) I need to select cells from H3 to Mxxx where total rows are variable and unknown

2) I need to convert those values from Text to Number

I found this much code and it works for any selection that I manually highlight.  But I'm having trouble with number #1.

    '   Check to see if selection is formatted as Text -
    '   If so, then reformat selection as General
    '**********************************************************
    If Selection.NumberFormat = "@" Then _
            Selection.NumberFormat = "General"
           
    '   Replace formulas and numeric strings with real numbers
    '**********************************************************
    Selection.Value = Selection.Value
0
Comment
Question by:newknew
2 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 250 total points
ID: 38807901
To apply to the last populated cell in Col M...


Dim LastR As Long

With ActiveSheet
    LastR = .Cells(.Rows.Count, "m").End(xlUp).Row
    With .Range("h3:m" & LastR)
        .NumberFormat = General
        .Value = .Value
    End With
End With

Open in new window

0
 
LVL 1

Author Closing Comment

by:newknew
ID: 38810763
worked perfectly, thank you!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now