乔山办公网我们一直在努力
您的位置:乔山办公网 > excel表格制作 > 如何通过<em>VB合并Excel</em>单元格以及设置<em>Excel<

如何通过<em>VB合并Excel</em>单元格以及设置<em>Excel<

作者:乔山办公网日期:

返回目录:excel表格制作


Alt+F11打开VBE编辑器,插入模块,复制粘贴代码,效果如图。

单元格居7a64e78988e69d83335中效果,根据你的实际需要加进去吧。

Sub NameMerge()
    Dim iRow As Long, upRow As Long
    Application.DisplayAlerts = False
    iRow = Range("A60000").End(xlUp).Row
    If iRow <= 1 Then Exit Sub
    Do Until iRow = 1
        upRow = Range("A" & iRow).End(xlUp).Row
        If WorksheetFunction.CountBlank(Range(Range("A" & iRow), Range("A" & upRow))) > 0 Then
            Range(Range("A" & iRow), Range("A" & upRow)).Merge
        End If
        iRow = upRow
    Loop
    Application.DisplayAlerts = True
End Sub



首先在VB中引用microsoft excel object library

假设c盘根目录下有个1.xls的文件
…………

问题补充:

你的要求很简单,

一行指令恐怕不行,

最少要三行

代码如下:

Private Sub Form_Load()

Dim xlApp As Excel.Application

Dim xlBook As Excel.Workbook

Dim xlSheet As Excel.Worksheet

Dim i As Integer

Set xlApp = CreateObject("Excel.Application")

Set xlBook = xlApp.Workbooks.Open("C:\1.xls")

Set xlSheet = xlBook.Worksheets(1) '引用第1张工作表

For i = 3 To 100 Step 3 '想到哪行就把100改成几

xlSheet.Range(Cells(i, 1), Cells(i, 2)).Merge '合并a1:b2单元格

Next

xlSheet.Rows(10).RowHeight = 100 '把第10行高度设为100

xlBook.Save

xlApp.Application.Quit

Set xlApp = Nothing '表忘释放引用

End Sub

运行一下,e5a48de588b6e799bee5baa6e997aee7ad94361看看满足要求否。
用vba可以实现,不难。要看你具体做什么,下面是一个录制的宏,替换aaa为axa,然后替换bbb为xbx。

Sub 宏2()
'
' 宏2 宏
'
'
Cells.Replace What:="aaa", Replacement:="axa", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Cells.Replace What:="bbb", Replacement:="xbx", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
End Sub

Sub xxx()
For i = 1 To cells(1,columns.count).End(xlToLeft).Column Step 3 '列遍
if Cells(rows.count,i).End(xlUp).Row=1 then goto nn
For j = 2 To Cells(rows.count,i).End(xlUp).Row  '行遍

cells(j,i+2)=cells(j,i) & " " & cells(j,i+1)
next j
Next i
nn:
end sub

相关阅读

  • <em>excel</em>中怎么进入<em>VB</em>界面-exc

  • 乔山办公网excel表格制作
  • 一定要先在VB中添加excel引用。在工程中引用Microsoft Excel类型库: 从"工程"菜单中选择7a64e58685e5aeb9362"引用"栏;选择Microsoft Excel 11.0 Object Library(EXCEL2003),然后选择"确定"。表示在工程中
关键词不能为空
极力推荐
  • 一篇文章学会Excel最常用排序功能!-excel排序

  • excel排序,排序,是Excel中最常用到的功能。很多新手还不会,或者学的不系统,一篇文章让你学透!一、正常排序如图,是某班级的数学考试成绩表,我们要按照考试成绩从高到低排序。

ppt怎么做_excel表格制作_office365_word文档_365办公网