Macro to pull data from A2:K2

B.Kellough

Board Regular
Joined
Aug 1, 2009
Messages
180
I'm needing a macro that will pull data from A2:K2 and remove everything from the data except for the numbers only. for example A2 has "|16.51%" in the cell, the macro would remove "|" and "%" and leave the 16.51 and remove any spaces before the 16.51.

Thanks in advance for any help with this.
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
let me know if this works for you
PHP:
Sub Macro1()
    With Range("A2:K2")
        .Replace What:="%", Replacement:="", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        .Replace What:="|", Replacement:="", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
        .Formula = Trim(.Text)
    End With
End Sub
 
Upvote 0
Wipes everything for me too. Why not just do the replaces (including one for spaces as mentioned in the OP)?

<font face=Courier New><br><SPAN style="color:#00007F">Sub</SPAN> Macro1()<br>    <SPAN style="color:#00007F">With</SPAN> Range("A2:K2")<br>        .Replace What:="%", Replacement:="", LookAt:=xlPart, _<br>            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=<SPAN style="color:#00007F">False</SPAN>, _<br>            ReplaceFormat:=False<br>        .Replace What:="|", Replacement:="", LookAt:=xlPart, _<br>            SearchOrder:=xlByRows, MatchCase:=<SPAN style="color:#00007F">False</SPAN>, SearchFormat:=False, _<br>            ReplaceFormat:=<SPAN style="color:#00007F">False</SPAN><br>        .Replace What:=" ", Replacement:="", LookAt:=xlPart, _<br>            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _<br>            ReplaceFormat:=False<br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br><br><br></FONT>
 
Upvote 0
Peter, that works perfectly. thanks

One question; I also have a foemula in M2 that is suppose to get the average of the numbers in A2:F2 and that has stopped working, any suggestions?
 
Upvote 0
Peter, that works perfectly. thanks

One question; I also have a foemula in M2 that is suppose to get the average of the numbers in A2:F2 and that has stopped working, any suggestions?
What exactly is the formula?
 
Upvote 0
Looks OK. You say it has "stopped working". What do you mean? What is showing in M2? What is in A2:F2?
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,729
Members
452,939
Latest member
WCrawford

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