Start string at same position in cell

nyconfidential

New Member
Joined
Jul 22, 2015
Messages
49
Office Version
  1. 365
  2. 2016
Hi all, I have a sheet that contains two sets of data in the same column. I need the second set to start at the same position each time, for example:

Red 5
Yellow 7
Blue 3

Red/5, etc would be in the same cell. Is there any way I can ensure that the numeric value always starts 10 characters in, no matter what is in the first column(obviously if I just hard coded some spaces in between the color and number the number's starting place would be affected by the number of characters in the color name). I have to do this one column. Thanks!
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
It seems like you want to replace the existing values in the column, so maybe something like this:
VBA Code:
Sub ProcessColumnA()
    Dim rng As Range, R As Range
    Dim SA As Variant

    With ActiveSheet
        Set rng = .Range("A1:A" & .Range("A" & .Rows.Count).End(xlUp).Row)
    End With

    For Each R In rng
        SA = Split(Application.Trim(R.Value), " ")
        If UBound(SA) = 1 Then
            R.Value = Left(SA(0) & Space(10), 9) & SA(1)    'Start numeric value at char #10
        End If
    Next R
End Sub
 
Upvote 0
Two data in one cell is just making work for yourself downstream.
I would recomend that you insert a column, move the numbers to that, with TextToColumns, and then use formatting to hide the grid lines and column Widths to your taste.
 
Upvote 0
Two data in one cell is just making work for yourself downstream.
I would recomend that you insert a column, move the numbers to that, with TextToColumns, and then use formatting to hide the grid lines and column Widths to your taste.

+1. What he said.
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,806
Members
449,048
Latest member
greyangel23

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