1、首先在开发工具中打开VBA编辑器
2、在单元格区域当中输入一些内容作为例子
3、在VBA编辑器中插入模块
4、在模块当中输入如下代码,然后运行Sub 合并居中() Dim i%, counts婊剧琏兄%, sTem$ Application.ScreenUpdating=FalseAppl足毂忍珩ication.DisplayAlerts=FalseRng_count=Selection.CountFor i=1 To Rng_count sTem=sTem & Selection.Cells(i)NextWith Selection .MergeCells=True .HorizontalAlignment=xlCenter .VerticalAlignment=xlCenter .NumberFormatLocal="@" .Value=sTemEnd WithApplication.DisplayAlerts=TrueApplication.ScreenUpdating=TrueEnd Sub
5、选中有数据的单元格A2∶C2,利用快捷键Alt+F8调出运行宏窗口,然后单击“执行”按钮,则单元格及数据均被合并