Excel VBA-行列操作

==========================

Sub 设置行列自适应()
    With Excel.ActiveSheet
        .Rows.AutoFit
        '.Columns.AutoFit
    End With
End Sub

==========================

Sub 批量调整行高()
'操作的时候注意选择单元格只能从上到下选择,因为这会影响Activecell的定位
    Dim iRow As Integer
    Dim i As Integer, r As Integer

    iRow = Selection.Rows.Count
    r = ActiveCell.Row
    '首先判断选择的区域是一个还是多个,仅一个区域的时候执行代码
    If Selection.Areas.Count = 1 Then
        For i = 1 To iRow
            Rows(r + i - 1).RowHeight = 40
        Next
    End If   
End Sub

==========================

Sub 控制行高最小值()
    Dim iRow As Integer
    Dim i As Integer, r As Integer

    iRow = Selection.Rows.Count
    r = ActiveCell.Row

    If Selection.Areas.Count = 1 Then
        For i = 1 To iRow
            If Rows(r + i - 1).RowHeight < 31.5 Then Rows(r + i - 1).RowHeight = 31.5
        Next
    End If
End Sub

==========================

==========================

==========================

==========================

==========================

==========================

Sub 选定区域合并相同内容单元格()
Application.Goto Reference:="Macro1"
Application.DisplayAlerts = False

    Set Rng = Selection
    With Rng
        For i = Rng.Rows.Count To 2 Step -1
            If Rng.Cells(i - 1, 1) = Rng.Cells(i, 1) Then
                Rng.Range(Cells(i - 1, 1), Cells(i, 1)).Merge
            End If
        Next
    End With

Application.DisplayAlerts = True
End Sub

==========================

==========================

==========================

==========================

==========================

==========================

==========================

==========================

 

 
 
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值