Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Select Range and Convert Text to Numbers in Excel VBA

Posted on 2013-01-22
2
Medium Priority
?
447 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 93

Accepted Solution

by:
Patrick Matthews earned 1000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

715 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