Excel VBA之合并单元格操作
时 间:2012-08-08 09:01:26
作 者:叶海峰 ID:31 城市:广州
摘 要:Excel VBA之合并单元格操作。
正 文:
Sub mergecells() '自动合并单元格
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim cell As Range
Dim i, b As Integer
i = Selection.Rows.count - 1
For b = 1 To i
With ActiveCell
.Select
If .Offset(1, 0) = .Value Then
Range(ActiveCell, .Offset(1, 0)).Select
Selection.mergecells = True
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
Else
.Offset(1, 0).Select
End If
End With
Next
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
Sub mergecells_insertvalue() '自动拆分合并单元格+填充值
Application.ScreenUpdating = False
Application.DisplayAlerts = False
On Error GoTo tuichu
Dim cell As Range
Dim i, a As Integer '填充上一行值
Dim j, k As Byte
Dim rng As String
i = Selection.Rows.count
k = Selection.Columns.count
For Each cell In Selection
If cell.mergecells = True Then
cell.mergecells = False
End If
Next
rng = ActiveCell.Address
For j = 0 To k - 1
For a = 1 To i
With ActiveCell
If .Value = "" Then
.Offset(-1, 0).Copy
.PasteSpecial xlPasteAll
End If
.Offset(1, 0).Select
End With
Next
Range(rng).Offset(0, j + 1).Activate
Next
Application.ScreenUpdating = True
Application.DisplayAlerts = True
tuichu:
End Sub
Sub 拆分合并单元格_填充平均值()
Dim ma As Range
Dim a As Variant
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each rng In Selection
a = rng.Value
If rng.mergecells = True Then
Set ma = rng.MergeArea
rng.mergecells = False
Range(ma.Address) = a / ma.Cells.count
End If
Next
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
演 示:
Access软件网官方交流QQ群 (群号:54525238) Access源码网店
常见问答:
技术分类:
源码示例
- 【源码QQ群号19834647...(12.17)
- 【Access选项卡示例】Ac...(09.09)
- 【Access源码示例】按输入...(09.02)
- 【Access日期区间段查询】...(08.29)
- 【Access日期区间段查询】...(08.27)
- Access怎样才能实现日期时...(08.21)
- 【Access定时打开查询】A...(08.19)
- Access生成固定数量的记录...(08.13)
- Access怎样才能实现日期时...(08.12)
- Access利用导航窗体控件对...(08.03)
学习心得
最新文章
- Access快速开发平台--更改“...(09.18)
- 【中秋及国庆优惠】Access培训...(09.15)
- Access如何将日期型的数值转换...(09.14)
- 英文输入法输入数据中存在单引号引起...(09.11)
- 【Access选项卡示例】Acce...(09.09)
- 让Access光标停留在指定的控件...(09.07)
- 关于Access查询条件里使用通配...(09.06)
- Access报表偷懒制作法--Ac...(09.05)
- Access快速开发平台--窗体数...(09.04)
- 【Access源码示例】按输入的日...(09.02)