Replacing text or separting into 2 or more columns

MrByte

Board Regular
Joined
Feb 9, 2007
Messages
167
Office Version
  1. 365
I have a general idea where I want to go with this. But I am looking for guideance on how to do it.

I have a column with something like this: 5 of 10* or 245 of 390

I want to separate this into two or more columns. Sure I can easily do it with a formula or even the Text to Columns menu option. But I would like to do it with a macro.

The two numbers are going into two columns the * will be replaced with RO.

Thanks for the help in advance.
 
Hello,

does this work as expected?

Code:
Sub TXT_TO_COLS()
    Columns("A:A").TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=False, _
        Semicolon:=False, Comma:=False, Space:=True, Other:=True, OtherChar:= _
        "_", FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3, 1)), _
        TrailingMinusNumbers:=True
    Columns("B:B").Select
    Selection.Delete Shift:=xlToLeft
    For MY_ROWS = 1 To Range("A65536").End(xlUp).Row
        If Right(Range("B" & MY_ROWS).Value, 1) = "*" Then
            Range("C" & MY_ROWS).Value = "RO"
            Range("B" & MY_ROWS).Value = Left(Range("B" & MY_ROWS).Value, Len(Range("B" & MY_ROWS).Value) - 1)
        End If
    Next MY_ROWS
End Sub
 
Upvote 0
Yep! Did exactly what I wanted. Although I was tyring to figure out the code myself. This worked fine. Now I just need to figure out what you did. I am still pretty basic when it comes to coding.
 
Upvote 0

Forum statistics

Threads
1,226,878
Messages
6,193,465
Members
453,802
Latest member
SarahNoob

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