Extract row if cell contains certain number of backslashes

Sanderfox

New Member
Joined
Dec 30, 2013
Messages
2
Hi,

I'm new here, but I'm hoping you can help me with the following problem.

Example table:

A
B
C
D
1
Directory
Size (MB)
Files
Folders
2
\\example\home\user1\
12
20
3
3
\\example\home\user1\A\
2
2
0
4
\\example\home\user1\B\
5
9
0
5
\\example\home\user1\C\
5
9
0
6
\\example\home\user2\
10
30
2
7
\\example\home\user2\A\
6
20
0
8
\\example\home\user2\B\
4
10
0
9
\\example\home\user3\
20
50
2
10
\\example\home\user3\A\
12
10
0
11
\\example\home\user3\B\
8
40
0

<tbody>
</tbody>

What I would like to do:
Extract rows where the cell in column A contains exactly 5 backslashes to another worksheet. In the example that would be rows 2, 6 and 9.

The array formula that I have so far:
=IF(LEN(A2)-LEN(SUBSTITUTE(A2,"\",""))=5,INDEX(A$2:A$11,SMALL(IF(LEN(A2)-LEN(SUBSTITUTE(A2,"\",""))=5,ROW($A$2:$A$11)-ROW($A$2)+1),ROWS(Sheet2!A$2:A2))),"")

Problem:
The rows are extracted, but have gaps between them. I would like to see:

A
B
C
D
1
Directory
Size (MB)
Files
Folders
2
\\example\home\user1\
12
20
3
3
\\example\home\user2\
10
30
2
4
\\example\home\user3\
20
50
2

<tbody>
</tbody>

Instead of what I get now:

A
B
C
D
1
Directory
Size (MB)
Files
Folders
2
\\example\home\user1\
12
20
3
3
4
5
6
\\example\home\user2\
10
30
2
7
8
9
\\example\home\user3\
20
50
2
10
11

<tbody>
</tbody>

Question:
How can I adjust my formula so that the extracted rows appear as in my second example?

Thank you in advance for any assistance.

All the best,
Sander
 

Some videos you may like

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

Weazel

Well-known Member
Joined
Dec 24, 2011
Messages
3,155
maybe....?


Excel 2012
ABCD
1DirectorySize (MB)FilesFolders
2\\example\home\user1\12203
3\\example\home\user1\A\220
4\\example\home\user1\B\590
5\\example\home\user1\C\590
6\\example\home\user2\10302
7\\example\home\user2\A\6200
8\\example\home\user2\B\4100
9\\example\home\user3\20502
10\\example\home\user3\A\12100
11\\example\home\user3\B\8400
12
13DirectorySize (MB)FilesFolders
14\\example\home\user1\12203
15\\example\home\user2\10302
16\\example\home\user3\20502

<tbody>
</tbody>
Sheet1

Array Formulas
CellFormula
A14{=IFERROR(INDEX(A$2:A$11,SMALL(IF(LEN($A$2:$A$11)-LEN(SUBSTITUTE($A$2:$A$11,"\",""))=5,ROW($A$2:$A$11)-ROW($A$2)+1),ROWS(A$14:A14))),"")}
B14{=IFERROR(INDEX(B$2:B$11,SMALL(IF(LEN($A$2:$A$11)-LEN(SUBSTITUTE($A$2:$A$11,"\",""))=5,ROW($A$2:$A$11)-ROW($A$2)+1),ROWS(B$14:B14))),"")}
C14{=IFERROR(INDEX(C$2:C$11,SMALL(IF(LEN($A$2:$A$11)-LEN(SUBSTITUTE($A$2:$A$11,"\",""))=5,ROW($A$2:$A$11)-ROW($A$2)+1),ROWS(C$14:C14))),"")}
D14{=IFERROR(INDEX(D$2:D$11,SMALL(IF(LEN($A$2:$A$11)-LEN(SUBSTITUTE($A$2:$A$11,"\",""))=5,ROW($A$2:$A$11)-ROW($A$2)+1),ROWS(D$14:D14))),"")}

<tbody>
</tbody>
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself

<tbody>
</tbody>
 

Watch MrExcel Video

Forum statistics

Threads
1,122,499
Messages
5,596,517
Members
414,074
Latest member
Matthew Kakde

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
Top