Re: [問題] excel合併儲存格
請試試看以下的 VBA 囉
Option Explicit
Sub Macro1()
Dim i As Integer
Dim j As Integer
Dim prei As Integer
Dim rCount As Integer
Dim a As String
Dim b As String
Dim c As String
Application.ScreenUpdating = False
Application.DisplayAlerts = False
With ThisWorkbook.Sheets(1)
rCount = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
a = .Cells(1, 1)
b = .Cells(1, 2)
c = .Cells(1, 3)
prei = 1
For i = 1 To rCount
If .Cells(i, 1) <> a Or .Cells(i, 2) <> b Or _
.Cells(i, 3) <> c Then
For j = 1 To 3
Range(Cells(prei, j), Cells(i - 1, j)).Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = True
End With
Next j
a = .Cells(i, 1)
b = .Cells(i, 2)
c = .Cells(i, 3)
prei = i
End If
Next i
.Cells(1, 1).Select
End With
Application.DisplayAlerts = True
Application.ScreenUpdating = True
MsgBox ("成功")
End Sub
※ 引述《copyme21 (草莓)》之銘言:
: (若是和其他不同軟體互動之問題 請記得一併填寫)
: 軟體:excel
: 版本:2007
: 三民國小的20297的陳小明一筆,永福國小的21776的王大成四筆,
: 以此類推,請問有什麼方法,快速把不規則的合併儲存格做處理?
: 資料有五、六百筆,之前用手工合併,費很多時間,
: 謝謝幫忙^^
: 原始資料:
: A B C D
: 1 三民國小 20297 陳小明 1
: 2 永福國小 21776 王大成 1
: 3 永福國小 21776 王大成 2
: 4 永福國小 21776 王大成 3
: 5 永福國小 21776 王大成 4
: 6 成德國小 20077 李玲玲 1
: 7 成德國小 20077 李玲玲 2
: 8 成德國小 20077 李玲玲 3
: 9 再興國小 20151 劉銘銘 1
: 合併儲存格後資料:
: A B C D
: 1 三民國小 20297 陳小明 1
: 2 永福國小 21776 王大成 1
: 3 2
: 4 3
: 5 4
: 6 成德國小 20077 李玲玲 1
: 7 2
: 8 3
: 9 再興國小 20151 劉銘銘 1
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.131.84.78
推
12/26 21:20, , 1F
12/26 21:20, 1F
→
12/28 09:29, , 2F
12/28 09:29, 2F
討論串 (同標題文章)
Office 近期熱門文章
PTT數位生活區 即時熱門文章
11
38