My current solution to removing all non numeric characters from cells in a specific column (AK) takes my code 7 minutes to run for 360 rows. When I Run the code selecting the all 360 cells with 'application selection' it only takes 10 seconds to run. Optimally I would like to have the Macro select the criteria on its own. Please note the data is pulled in from a query though excel.
I have searched the web, but found nothing where the code selects the column on its own. The Code I created on my own takes 7 minutes vs 10 seconds.
The below code takes 7 minutes to run, but doesn't require the user to select the data.
Dim finRow As String
finRow = ActiveSheet.Range("A100000").End(xlUp).Row
Set myRange = ActiveSheet.Range("AK2:AK" & finRow)
For Each myCell In myRange
LastString = ""
For I = 1 To Len(myCell.Value)
mT = Mid(myCell.Value, I, 1)
If mT Like "[0-9]" Then
tString = mT
Else
tString = ""
End If
LastString = LastString & tString
Next I
myCell.Value = LastString
Next
The Code below takes 10 seconds but the user will have to select the criteria each time the code is run.
Set myRange = Application.Selection
Set myRange = Application.InputBox("select one Range that you want to remove non numeric characters", "RemoveNonNum", myRange.Address, Type:=8)
For Each myCell In myRange
LastString = ""
For I = 1 To Len(myCell.Value)
mT = Mid(myCell.Value, I, 1)
If mT Like "[0-9]" Then
tString = mT
Else
tString = ""
End If
LastString = LastString & tString
Next I
myCell.Value = LastString
Next
I expect the output to be 10 seconds when the code selects the criteria on its own. I appreciate all the help. Thank you, Matt