Sub s()
ActiveSheetUsedRangeNumberFormatLocal = "@"
Set rg1 = Intersect([b:b], ActiveSheetUsedRange)
Set rg2 = Intersect([a:a], ActiveSheetUsedRange)
ActiveSheetSortSortFieldsClear
ActiveSheetSortSortFieldsAdd Key:=rg1, SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
ActiveSheetSortSortFieldsAdd Key:=rg2, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveSheetSort
SetRange ActiveSheetUsedRange
Header = xlGuess
MatchCase = False
Orientation = xlTopToBottom
SortMethod = xlPinYin
Apply
End With
End Sub
选中目标单元格,执行下面的过程即可
Option ExplicitSub GetMultiLine()
Dim OStr As String, OLen As Integer
OStr = ActiveCellValue
OLen = Len(OStr)
If OLen = 0 Then
MsgBox "空单元格"
Exit Sub
End If
'单元格非空时获取换行符,并获取单元格内各行文本
Dim arrStr() As String, CvtASC As Long, i As Integer
Dim arrLineLoc() As Integer
Dim arrNewStr() As String, j As Integer
For i = 1 To OLen
ReDim Preserve arrStr(1 To i)
arrStr(i) = Mid(OStr, i, 1)
CvtASC = Asc(arrStr(i))
If CvtASC = 10 Then
j = j + 1
ReDim Preserve arrLineLoc(1 To j)
arrLineLoc(j) = i
End If
Next
j = j + 1
ReDim Preserve arrLineLoc(1 To j)
arrLineLoc(j) = OLen + 1
For i = 1 To j
ReDim Preserve arrNewStr(1 To i)
If i = 1 Then
arrNewStr(i) = Mid(OStr, 1, arrLineLoc(i) - i)
Else
arrNewStr(i) = Mid(OStr, arrLineLoc(i - 1) + 1, arrLineLoc(i) - arrLineLoc(i - 1) - 1)
End If
Next
'输出结果
Dim NoOfLine As Integer, OutStr As String
NoOfLine = UBound(arrNewStr)
For i = 1 To NoOfLine
OutStr = OutStr & arrNewStr(i) & vbCr
Next
OutStr = "单元格内共有 " & NoOfLine & "行" & vbCr & OutStr
MsgBox OutStr
End Sub
1、第一种方法: ActiveSheetRange("A" & RowsCount)End (xlUp)Row
2、第二种方法:ActiveSheetRange("a1048576")End(xlUp)Row
如果是低版本的OFFICE用ActiveSheetRange("a65536")End(xlUp)Row
3、第三种方法:ActiveSheetCells(RowsCount,1)End(3)Row
4、第四种方法:ActiveSheetrange("A1")CurrentRegionRowsCount
5、第五种方法:ActiveSheetCellsSpecialCells(xlCellTypeLastCell)Row
6、第六种方法:ActiveSheetUsedRangeSpecialCells(xlCellTypeLastCell)Row
7、第七种方法:MaxRow =ApplicationEvaluate("=MAX((A1:A1048576<>"""")ROW(1:1048576))")
以上就是关于excel vba移动行按条件全部的内容,包括:excel vba移动行按条件、Excel VBA 单元格设置好为自动换行。问:怎样获取单元格内共有多少行怎样获取单元格内各行文、如何在vba中得到当前单元格的行号和列号等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)