Anonymous
Anonymous asked in 電腦與網際網路軟體 · 9 years ago

Excel VBA 自動判斷欄位資料重複並合併儲存格

各位前輩,小弟在尋找此問題時,洽巧發現01網友:d8529307與小救有同樣問題,故將問題轉貼過來,請前輩賜教,感激不盡。

---------------------------------------------------------------------

我想在A欄中,已經依序排列,但是每項數量不定的資料中,自行判斷資料是否重複;若是,則合併儲存格。

請問在Excel VBA的語法要如何編輯,謝謝

圖片參考:http://kdsl.myweb.hinet.net/1.jpg

圖片參考:http://kdsl.myweb.hinet.net/2.jpg

1 Answer

Rating
  • Daniel
    Lv 7
    9 years ago
    Best Answer

    VBA程式碼:

    Sub TEST()

    R = 2

    R1 = R

    Application.DisplayAlerts = False

    While Cells(R, 1) <> ""

    If Cells(R, 1) <> Cells(R + 1, 1) Then

    R2 = R

    With Range("A" & R1 & ":A" & R2)

    .HorizontalAlignment = xlCenter

    .VerticalAlignment = xlCenter

    .Merge

    End With

    R1 = R + 1

    End If

    R = R + 1

    Wend

    Application.DisplayAlerts = True

    End Sub

Still have questions? Get your answers by asking now.