Cell will number and text

outlawspeeder

Board Regular
Joined
Jan 17, 2009
Messages
225
Office Version
  1. 2019
I looking for a VBA way to pull and replace cells that have both text and numbers. I nee to do math with the numbers and put it back in to the cell. Not all the Cells have Text. The ones without text, there is no need for math.

123 xyz ----->123*2--------->246
234----------------------------->234
2-------------------------------->2
24xyz---------->24*2---------->28
8809 abc----->8809*2------->17618

Thanks
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Are the letters following the numbers always 3 characters long? On 1 example you have a number followed by the letters with no space, but the other 2 are separated by a space. Do you have them both ways?
 
Upvote 0
with Power Query
RawResult
123 xyz246
234234
22
24xyz48
8809 abc17618

Rich (BB code):
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Text = Table.AddColumn(Table.TransformColumnTypes(Source,{{"Raw", type text}}), "Text", each Text.Select([Raw],{"0".."9"})),
    TypeNumber = Table.TransformColumnTypes(Table.AddColumn(Text, "Number", each Text.Select([Raw],{"0".."9"})),{{"Number", Int64.Type}}),
    Result = Table.AddColumn(TypeNumber, "Result", each if [Raw] = [Text] then [Number] else [Number]*2),
    TSC = Table.SelectColumns(Result,{"Result"})
in
    TSC
 
Upvote 0
Is the rule to multiply any number followed by text times two (always two)?
 
Upvote 0
It will always be the same number (not 2) The number is 28. I used 2 only for the sample.

"Rich BB Code" I can follow it but I don't understand it.


Thanks
 
Upvote 0
Give this macro a try (change the range to meet your actual needs)...
VBA Code:
Sub Test()
  Dim Cell As Range
  Application.ScreenUpdating = False
  For Each Cell In Range("A1:A6")
    If Cell.Value Like "*[!0-9]*" Then
      Cell.Value = 28 * Val(Cell.Value)
    End If
  Next
  Application.ScreenUpdating = True
End Sub
 
Upvote 0
Rick: It will always be the same number (not 2) The number is 28. I used 2 only for the sample.

Sandy: "Rich BB Code" I can follow it but I don't understand it. And if Power Query is an add in, I using a lock down computer, software, addins… Well I got VB but only if I save the file as a .xls (2003)


I can not update what ver here at work due to the check box being images are blocked. Vers I use 2019, 365, 2016, 2010 and file types for 2003 running 2016.. My life is fun
 
Upvote 0

Forum statistics

Threads
1,215,378
Messages
6,124,604
Members
449,174
Latest member
ExcelfromGermany

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