看板 Office 關於我們 聯絡資訊
軟體:excel 版本:2007 我有一個表 A x A x A y B y B x C k C k C x D x D x D y 想要儲存格合併的時候 B欄位依照A欄位合併 現在的巨集會變成B欄位的就合併一起 檔案如附件: https://drive.google.com/open?id=1HC3AC-tunGI2MTeLfxkEtE_f0dcT0ZeL 我用巨集如下 Dim xR As Range, xH As Range For Each xR In Range([A1], [A65536].End(xlUp)) If xR <> xR(0) Then Set xH = xR If xR <> xR(2) Then Range(xR, xH).Merge Next For Each xR In Range([b1], [b65536].End(xlUp)) If xR <> xR(0) Then Set xH = xR If xR <> xR(2) Then Range(xR, xH).Merge Next 不知道這塊要怎麼改 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 60.250.67.78 ※ 文章網址: https://www.ptt.cc/bbs/Office/M.1533095880.A.550.html
soyoso: https://i.imgur.com/gTRH3jb.jpg 類似這樣 08/01 12:12
soyoso: 連結為a欄的部分,但應先從b欄判斷;b欄和a欄差別上為b欄 08/01 12:13
soyoso: 會多個或於a欄下方儲存格是否相同,不相同的話則合併儲存 08/01 12:15
soyoso: 格 08/01 12:15
ptguitar: 感謝S大 實在太強大了 還要研究看看 08/01 13:52
後來研究似乎還是沒有達到我效果 檔案如下: https://drive.google.com/open?id=1mBYyWgj9aLnM88gBGQKpnctb-b-dThRG ※ 編輯: ptguitar (60.250.67.78), 08/01/2018 14:11:29 ※ 編輯: ptguitar (60.250.67.78), 08/01/2018 14:28:22
soyoso: 連結內無看到b欄的寫法,也請附上,才清楚沒有達到效果的 08/01 14:47
soyoso: 原因 08/01 14:47
我後來用自己比較容易理解方式來寫 感謝S大提供想法 Sub test() Dim row1 As Integer ActiveSheet.Select Application.DisplayAlerts = False row1 = Range("C65536").End(xlUp).Row For i = row1 To 2 Step -1 If Cells(i, 2).Value = Cells(i - 1, 2).Value And Cells(i, 1).Value = Cells(i - 1, 1) Then Range(Cells(i - 1, 2), Cells(i, 2)).Merge End If Next i For i = row1 To 2 Step -1 If Cells(i, 1).Value = Cells(i - 1, 1).Value Then Range(Cells(i - 1, 1), Cells(i, 1)).Merge End If Next i Application.DisplayAlerts = True End Sub ※ 編輯: ptguitar (60.250.67.78), 08/01/2018 15:02:29 ※ 編輯: ptguitar (60.250.67.78), 08/01/2018 15:03:26
soyoso: https://i.imgur.com/iJ391ao.jpg 08/01 15:12
soyoso: 上述為回文的想法用於for..next;測試以原po所貼的巨集結 08/01 15:17
soyoso: 果應也可以達成 08/01 15:17
soyoso: 如以回文想法用於for each..next的話 08/01 15:17
soyoso: https://i.imgur.com/uHNUjJT.jpg 08/01 15:17
ptguitar: for each的方式看網路寫法 不過不太好懂 再來研究看看 08/01 15:26
soyoso: 以原文範例for..next如要正序寫法,可配合工作表函數 08/01 15:29
soyoso: countif和countifs https://i.imgur.com/UDGqM0h.jpg 08/01 15:29