簡體   English   中英

EXCEL-宏可根據單元格值有條件地合並行

[英]EXCEL - Macro to conditionally merge rows based on cell value

我在一個VBA宏后面,如果當前行的Col C內容為空,它將合並當前行的內容與上一行的內容

Input
Col A  | Col B  | Col C 
text1A | text1B | 1
text2A | text2B | 
text3A | text3B | 
text4A | text4B | 2
text5A | text5B | 

Output
Col A                | Col B                 | Col C 
text1A text2A text3A | text1B text2B test3B  | 1
text4A text5A        | text4B text5B         | 2

有類似的問題,但是我對VBA的了解太基礎了,無法將響應應用於此特定案例。 謝謝!

我認為這個問題將幫助您找到所需的解決方案。您的問題幾乎是重復的問題。

Sub mergeCategoryValues()
Dim lngRow As Long

With ActiveSheet
    lngRow = .Cells(65536, 1).End(xlUp).Row
    .Cells(1).CurrentRegion.Sort key1:=.Cells(1), Header:=xlYes

    Do
        If .Cells(lngRow, 1) = .Cells(lngRow - 1, 1) Then
            .Cells(lngRow - 1, 3) = .Cells(lngRow - 1, 3) & "; " & .Cells(lngRow, 3)

            .Rows(lngRow).Delete
        End If

        lngRow = lngRow - 1
    Loop Until lngRow = 1
End With
End Sub

這段代碼對我有用。答案發布在這里的問題上

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM