乔山办公网我们一直在努力
您的位置:乔山办公网 > excel表格制作 > 各位高手,请教一下 用<em>VBA</em>设置单元格的格式为“<em>自动换行&

各位高手,请教一下 用<em>VBA</em>设置单元格的格式为“<em>自动换行&

作者:乔山办公网日期:

返回目录:excel表格制作


拷贝上面的程序到你的excel宏中运行zhidao,将会把sheet1中E4:M5区域中的数据以行优先的方式逐行拷贝到sheet2中的C2:E7区域中,拷贝三个数后自动换行。如果源区域或目标区域不同,只需按注释修改相应变量的值。

录制一下宏就有了。
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlCenter
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
=========
就是这一句改一下:range("A1").WrapText = True
关键在a的值, 不知你的cells(3,4).value是什么?
建议用以下语句:

a=[b65536].end(xlup).row+1

Private Sub Worksheet_Change(ByVal Target As Range)
r = Target.Row
If Len(Cells(r, 5)) > 0 And Target.Column < 5 Then
Application.EnableEvents = False
If Len(Cells(r + 1, 1)) = 0 Then
Cells(r + 1, 1) = Cells(r, 5)
Cells(r, 5) = ""
Application.EnableEvents = True
Else
If Len(Cells(r + 1, 4)) = 0 Then
Range("A" & r + 1).Insert xlShiftToRight
Cells(r + 1, 1) = Cells(r, 5)
Cells(r, 5) = ""
Application.EnableEvents = True
Else
Range("A" & r + 1).Insert xlShiftToRight
Application.EnableEvents = True
Cells(r + 1, 1) = Cells(r, 5)
Cells(r, 5) = ""
End If
End If
End If
End Sub

相关阅读

关键词不能为空
极力推荐

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