Объединить две строки конкретного столбца, если данные одинаковы? - PullRequest
0 голосов
/ 21 мая 2018

У меня есть ввод, как показано ниже

enter image description here

Мне нужен вывод, как показано ниже

В основном, как объединить только столбец A смежных значений, еслиданные совпадают с формулой?Это огромный лист.Я хочу применить формулу, чтобы задача была автоматизирована.

enter image description here

1 Ответ

0 голосов
/ 21 мая 2018
Sub G()

    Dim x&, start&, bottom&
    Application.DisplayAlerts = False

    '// Start from row two
    '// In your sample it's value "Text1"
    x = 2

    While Not IsEmpty(Cells(x, 1))

        '// "start" designates the start row with new text (see below)
        start = x

        '// As soon as we defined start row with new text, it's time to define the last row.
        '// Cells(x, 1) - is new text value
        '// SearchDirection:=xlPrevious means that search must be done from bottom of sought range
        '// This also means that no extra data must be under your data.
        '// So, this way we can get to know full range.
        '// For single distinct value the start and bottom will be the same row.
        bottom = Range("A:A").Find(Cells(x, 1), SearchDirection:=xlPrevious).Row

        '// Having start and bottom rows,
        '// we can get full range with new text by using Resize property.
        '// It sets new number of rows and columns having top-left cell as a start point.
        Cells(start, 1).Resize(bottom - start + 1).Merge

        '// The next cell after bottom cell is new value.
        x = bottom + 1

    Wend

    Application.DisplayAlerts = True

End Sub
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...