Domanda

I've imported the results of a broken link search in to Excel and I now need to sort the results based on the error code. I can't get my head around how to do this because the error code is in the row below the URL and not in a column next to it. Also, some URLs take up more than one row.

Here is a screenshot of part of the spreadsheet:

results in excel

How would I go about grouping all results with error 404 together?

È stato utile?

Soluzione 2

Insert a column to the left of A and fill in with a sequence of numbers (1, 2, 3, ...). Now sort by column B. Select all the error code entries and drag them to column c (or some other empty column). Resort the sheet by the sequence of numbers in column A. Now with everything ordered and the error codes is a separate column (C), you can right-click on C1, and select shift cells up. Column A can be deleted, and you can sort by the URL's (although it looks like you clean up the text a bit).

Altri suggerimenti

Below you'll find a VBA code that do what you need. As I don't have the original sheet I create an excel and put some random data. Works fine for me.

Sub test()
    Dim row, rowDest, rowAux As Integer
    Dim source As Worksheet
    Dim dest As Worksheet

    'Replace here by the name of the worksheet that contains the data
    Set source = Worksheets("Sheet1")

    'This is the sheet where the modified data will be placed
    Set dest = Worksheets("Sheet2")

    'Start row (source sheet)
    row = 1

    'Start row (dest sheet)
    rowDest = 1

    'This is an auxiliary variable used to fill the error code column
    rowAux = 0

    'Go to the last line (column 1) of your source sheet and write the string !q
    'This will be used as a flag to know where your data finish
    While (source.Cells(row, 1).Value <> "!q")
        If (InStr(source.Cells(row, 1).Value, "http") > 0) Then
            dest.Cells(rowDest, 1).Value = source.Cells(row, 1).Value
            If (rowAux = 0) Then rowAux = rowDest
            rowDest = rowDest + 1
        ElseIf (InStr(source.Cells(row, 1).Value, "error code") > 0) Then
            While (dest.Cells(rowAux, 1).Value <> "")
                dest.Cells(rowAux, 2).Value = source.Cells(row, 1).Value
                rowAux = rowAux + 1
            Wend

            rowAux = 0
        End If

        row = row + 1
    Wend
End Sub

My dataset and results:

Source sheet:

Source sheet

Dest sheet:

Dest sheet

This is going to be difficult to do unless you can get the error code in the same row as the URL. However, you can still do it by using the SEARCH function on the error code. This will find the 404 error, but it won't give you the URL in the cell beneath it. Therefore, you need a function that checks to see if the cell beneath it's cell has found a 404 code. Then you can filter on the "true" values and get two rows.

Create a new column in A, and use the function below.

=IF(ISNUMBER(SEARCH("404",B1)),1,IF(A2=1,2,0))

Filter down on 1 and 2 values.

Solution based on http://office.microsoft.com/en-us/excel-help/check-if-a-cell-contains-text-HP003056106.aspx and the function:

=IF(ISNUMBER(SEARCH("v",A2)),"OK", "Not OK")

Subject to some constraints (but they are not in your Q!) this formula in an inserted ColumnA may serve:

=INDEX(C1:C3,MATCH("*error code:*",C1:C3,0))  

along with =ROW() in an inserted ColumnB (though could be elsewhere) and both copied down at the same time.

The formulae should be converted to values (copy ColumnsA:B, Paste Special..., Values over the top) and sorting be based on ColumnA then ColumnB. The rows blank in ColumnC may be deleted, as also those with error codes in that column.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top