How to group excel items based on custom rules?

后端 未结 3 1896
感动是毒
感动是毒 2021-01-19 16:39

I have a set of data (webmaster tools search queries) which is in excel with the following header:

Query | Impressions | Clicks | Date

Sample go

3条回答
  •  别那么骄傲
    2021-01-19 16:51

    This small macro assumes your data is in Sheet1 and your rules are in worksheet rules in columns A & B:

    Sub catagorize()
        Dim s1 As Worksheet, s2 As Worksheet
        Dim N1 As Long, N2 As Long
        Set s1 = Sheets("Sheet1")
        Set s2 = Sheets("rules")
        N1 = s1.Cells(Rows.Count, "A").End(xlUp).Row
        N2 = s2.Cells(Rows.Count, "A").End(xlUp).Row
        For i = 2 To N1
            v = s1.Cells(i, 1).Value
            For j = 1 To N2
                If InStr(1, v, s2.Cells(j, 1).Value) > 0 Then
                    s1.Cells(i, "D").Value = s2.Cells(j, "B").Value
                End If
            Next j
        Next i
    End Sub
    

提交回复
热议问题