Extracting cells containing certain characters

MikeH93

New Member
Joined
Jul 21, 2015
Messages
5
I have a lot of data in cells but I am really only interested in certain cells. I want to extract the cell in each row which contains a "-" (there is one in each row) and move them into a column of their own. The entries containing the "-" are not adjacent which makes it tricky to move all of them. I can select all the cells using the find function but then I can't copy all selected cells and as far as I am aware none of the FIND or SEARCH functions can help me.

What I have:

[TABLE="width: 500"]
<tbody>[TR]
[TD]1[/TD]
[TD]2[/TD]
[TD]3[/TD]
[TD]4[/TD]
[TD]5[/TD]
[/TR]
[TR]
[TD]27[/TD]
[TD]45[/TD]
[TD]36-X[/TD]
[TD]23[/TD]
[TD]15[/TD]
[/TR]
[TR]
[TD]34[/TD]
[TD]56[/TD]
[TD]23[/TD]
[TD]34[/TD]
[TD]67-Y[/TD]
[/TR]
[TR]
[TD]19[/TD]
[TD]54-P[/TD]
[TD]45[/TD]
[TD]12[/TD]
[TD]67[/TD]
[/TR]
</tbody>[/TABLE]

What I want to get:

[TABLE="width: 500"]
<tbody>[TR]
[TD]1[/TD]
[TD]2[/TD]
[TD]3[/TD]
[TD]4[/TD]
[TD]5[/TD]
[TD]Important Cells[/TD]
[/TR]
[TR]
[TD]27[/TD]
[TD]45[/TD]
[TD]36-X[/TD]
[TD]23[/TD]
[TD]15[/TD]
[TD]36-X[/TD]
[/TR]
[TR]
[TD]34[/TD]
[TD]56[/TD]
[TD]23[/TD]
[TD]34[/TD]
[TD]67-Y[/TD]
[TD]67-Y[/TD]
[/TR]
[TR]
[TD]19[/TD]
[TD]54-P[/TD]
[TD]45[/TD]
[TD]12[/TD]
[TD]67[/TD]
[TD]54-P[/TD]
[/TR]
</tbody>[/TABLE]

Given the range of tasks I've been able to perform using simple tricks and formulas, I thought this would be easy enough but having searched around, I still haven't found a solution. Would I have to look into using VBA or is there an intuitive way of getting this done? My VBA skills are very limited. Any help on the matter would be greatly appreciated.
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Hi,

Is it possible that there can be more than one cells with "-" in a row? In the above example you have one "-" cells for each row.
 
Upvote 0
Hi,

If there is only one cell with "-" in each row, try the following formula in F1:

=IF(ISERROR(SEARCH("-",A1)),IF(ISERROR(SEARCH("-",B1)),IF(ISERROR(SEARCH("-",C1)),IF(ISERROR(SEARCH("-",D1)),IF(ISERROR(SEARCH("-",E1)),"",E1),D1),C1),B1),A1)

drag this down the cells.

This is keeping in mind that you have the data in columns A:F
 
Upvote 0
Hi cbatrody. No there will only ever be one cell with one "-" in it for each row, just like the above scenario.
 
Upvote 0
Give this macro a try...
Code:
Sub ExtractDashedCells()
  Dim R As Long
  Application.ScreenUpdating = False
  For R = 2 To Cells(Rows.Count, "A").End(xlUp).Row
    Rows(R).Find("-", , , xlPart).Copy Cells(R, "F")
  Next
  Application.ScreenUpdating = True
End Sub
 
Upvote 0
I guess I'm now late to this post. Here was my script.
Code:
Sub TestMe()
Application.ScreenUpdating = False
Dim i As Integer
Dim b As Integer
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
    For i = 1 To Lastrow
        For b = 1 To 5
            If InStr(Cells(i, b).Value, "-") Then
                Cells(i, 6).Value = Cells(i, b).Value
                b = b + 1
            End If
        Next
    Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

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