2014-11-01 54 views
-1

我有這個表上的ExcelEXCEL:如何合併單元格有一定的價值

http://i.stack.imgur.com/N2kDS.png

,我想使這個樣子的,而是對所有列這樣做,因爲我有很多的行。

http://i.stack.imgur.com/1v0TE.png

+0

學習VBA,然後編寫一些在列中循環的代碼。這裏的邏輯是將非空白單元格存儲到一個變量中,並檢查當前迭代的單元格是否爲空。如果是這樣,請用存儲單元將其「聯合」。否則,合併到目前爲止所有單元格,並將新的非空單元格分配給變量。 – Manhattan 2014-11-01 09:37:53

回答

0

1-保存您的電子表格啓用宏。 (另存爲.XLSM) 2 - 打開視圖選項卡,單擊宏,宏查看和編輯 3-粘貼下面的代碼:

Sub Macro0() 
    'I assume your information is in the column A 
    With Range("A1:A65000") 

    'I also assume all CATEGORIES start with the word CATEGORY 
    'If that is not the case you have to define a list with all GATEGORIES 
    Set c = .Find("GATEGORY", LookIn:=xlValues) 

    If Not c Is Nothing Then 
     firstAddress = c.Address 
     oneBefore = firstAddress - 1 
     Do 
      Range("A1", oneBefore).Select 
      Selection.Merge 
      Set c = .FindNext(c) 
     Loop While Not c Is Nothing And c.Address <> firstAddress 
    End If 
    End With 

End Sub 

請注意我的代碼中的註釋。 讓我知道它是否適合你。

來源:http://msdn.microsoft.com/en-us/library/office/ff839746%28v=office.15%29.aspx

相關問題