Change column format to numbers (ignore blanks and text)

LeanneBG

Board Regular
Joined
Jun 20, 2016
Messages
157
Hi Experts - I looked around and was able to build below code.. My goal is to convert the format of the numbers found in column R (that are in general/text format) into number. The line item is changing so i don't have the "fixed" number of the last cell with data.

I also need the code to ignore blanks and texts/strings and to only convert the numbers. I was able to successfully do it using below code, however, it takes a long time (sometimes excel is already crashing) to do it because i think it is trying to look until the very last row of the excel (even those that has no data anymore). Can you please help check where i went wrong? Appreciate the help. Thank you in advance

Code:
Sub FormatCells()
Application.ScreenUpdating = False
Dim rng As Range, cell As Range, LastRowInR As Long






Set rng = ThisWorkbook.Sheets("SRPT").Range("R:R")


For Each cell In rng
    If Not IsError(cell.Value) Then _
        If Len(cell.Value) <> 0 And cell.HasFormula = False And _
            IsNumeric(cell.Value) Then cell.Value = Val(cell.Value)
Next cell


Application.ScreenUpdating = True
End Sub
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Hello,

To get the last you should following

Code:
[COLOR=#333333]LastRowInR = [/COLOR]ActiveSheet.Cells(Application.Rows.Count, "A").End(xlUp).Row

provided Column A has the correct number of Rows

then

Code:
[COLOR=#333333]Set rng = ThisWorkbook.Sheets("SRPT").Range("R2:R"& LastRowinR)[/COLOR]

Hope this will help
 
Upvote 0
Hello,

To get the last you should following

Code:
[COLOR=#333333]LastRowInR = [/COLOR]ActiveSheet.Cells(Application.Rows.Count, "A").End(xlUp).Row

provided Column A has the correct number of Rows

then

Code:
[COLOR=#333333]Set rng = ThisWorkbook.Sheets("SRPT").Range("R2:R"& LastRowinR)[/COLOR]

Hope this will help

it works! although still a little bit slow but much better compared to the first code. Thanks a lot James006!!
 
Upvote 0
Great ... :)

In order to speed up your macro :

Just insert as your first instruction :

Code:
Application.Calculation = xlCalculationManual

and as your last instruction :

Code:
Application.Calculation = xlCalculationAutomatic

Hope this will help
 
Upvote 0

Forum statistics

Threads
1,214,965
Messages
6,122,500
Members
449,090
Latest member
RandomExceller01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top