乔山办公网我们一直在努力
您的位置:乔山办公网 > excel表格制作 > <em>excel</em> <em>vba</em> 自动选择数据区域

<em>excel</em> <em>vba</em> 自动选择数据区域

作者:乔山办公网日期:

返回目录:excel表格制作


我这是自动找到最后一行的,符合你的要e5a48de588b6e799bee5baa6e79fa5e98193333求,请试试。

Private Sub CommandButton1_Click()
Dim row_last As Integer
Dim temp1 As Integer
Selection.SpecialCells(xlCellTypeLastCell).Select
flag = False
Do While flag = False
    If ActiveCell.Row = 1 Then
        Exit Do
    End If
    Selection.End(xlToLeft).Select
        temp1 = IsEmpty(ActiveCell.Value)
    Selection.End(xlToRight).Select
        temp2 = IsEmpty(ActiveCell.Value)
    If temp1 = True And temp2 = True Then
        Selection.Offset(-1, 0).Select
    Else
        flag = True
        Exit Do
    End If
Loop
Selection.End(xlToLeft).Select
row_last = ActiveCell.Row
Range(Cells(1, 1), Cells(row_last, 1)).Select
   Selection.PrintOut Copies:=1
End Sub

 



我的表格叫OMY,你的可以自己选
选中区域e799bee5baa6e79fa5e98193e78988e69d83334,然后进行了F1列的升序排列
我新百度知道,入学第一个任务,请给个满意答案
Range("F1:L16").Select
Selection.AutoFilter
ActiveWorkbook.Worksheets("OMY").AutoFilter.Sort.SortFields.Clear
ActiveWorkbook.Worksheets("OMY").AutoFilter.Sort.SortFields.Add Key:=Range( _
"F1:F16"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("OMY").AutoFilter.Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
使用inputbox()方法 ,如:inputbox("请用鼠标选择区域:“,type:=8),关键在于这个tpye,8代表的是range区域,详细可以见inputbox的帮助

Sub SelectDemo()
''选择M到S列有数据的区域
    Range("M2:S" & Cells(Cells.Rows.Count, 13).End(xlUp).Row).Select
''复制该区
    Selection.Copy
End Sub

相关阅读

关键词不能为空
极力推荐

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