Метод поиска
Sub FindMethod()
With ThisWorkbook.ActiveSheet
' First Used Row
Dim FirstUR As Long
If Not .Cells.Find("*", .Cells(.Rows.Count, .Columns.Count), -4123, , 1) _
Is Nothing Then _
FirstUR = .Cells.Find("*", .Cells(.Rows.Count, .Columns.Count)).Row
' First Used Column
Dim FirstUC As Integer
If Not .Cells.Find("*", .Cells(.Rows.Count, .Columns.Count), -4123, , 1) _
Is Nothing Then FirstUC = _
.Cells.Find("*", .Cells(.Rows.Count, .Columns.Count), , , 2).Column
' Last Used Row
Dim LastUR As Long
If Not .Cells.Find("*", .Cells(.Rows.Count, .Columns.Count), -4123, , 1) _
Is Nothing Then LastUR = .Cells.Find("*", , , , , 2).Row
' Last Used Column
Dim LastUC As Integer
If Not .Cells.Find("*", .Cells(.Rows.Count, .Columns.Count), -4123, , 1) _
Is Nothing Then LastUC = .Cells.Find("*", , , , 2, 2).Column
' First Used Cell (First Cell of the Used Range)
Dim FirstUCell As Range
If Not .Cells.Find("*", .Cells(.Rows.Count, .Columns.Count), -4123, , 1) _
Is Nothing Then Set FirstUCell = .Cells(.Cells.Find("*", _
.Cells(.Rows.Count, .Columns.Count)).Row, .Cells.Find("*", _
.Cells(.Rows.Count, .Columns.Count), , , 2).Column)
' Last Used Cell (Last Cell of the Used Range)
Dim LastUCell As Range
If Not .Cells.Find("*", .Cells(.Rows.Count, .Columns.Count), -4123, , 1) _
Is Nothing Then Set LastUCell = .Cells(.Cells.Find("*", , , , 1, 2) _
.Row, .Cells.Find("*", , , , 2, 2).Column)
' Used Range (Not UsedRange)
Dim URng As Range
If Not .Cells.Find("*", .Cells(.Rows.Count, .Columns.Count), -4123, , 1) _
Is Nothing Then Set URng = .Range(.Cells(.Cells.Find("*", _
.Cells(.Rows.Count, .Columns.Count)).Row, .Cells.Find("*", _
.Cells(.Rows.Count, .Columns.Count), , , 2).Column), .Cells(.Cells _
.Find("*", , , , 1, 2).Row, .Cells.Find("*", , , , 2, 2).Column))
' Usage - Rows, Columns
Debug.Print "First Used Row = " & FirstUR
Debug.Print "First Used Column = " & FirstUC
Debug.Print "Last Used Row = " & LastUR
Debug.Print "Last Used Column = " & LastUC
' Usage - Ranges
If Not FirstUCell Is Nothing Then
Debug.Print "First Used Cell Address = " & FirstUCell.Address
Else
Debug.Print "First Used Cell = Nothing (Empty Sheet)"
End If
If Not LastUCell Is Nothing Then
Debug.Print "Last Used Cell Address = " & LastUCell.Address
Else
Debug.Print "Last Used Cell = Nothing (Empty Sheet)"
End If
If Not FirstUCell Is Nothing Then
Debug.Print "Used Range Address = " & URng.Address
Else
Debug.Print "Used Range = Nothing (Empty Sheet)"
End If
' ' Some Thoughts:
' FirstUR = FirstUCell.Row
' FirstUC = FirstUCell.Column
' LastUR = LastUCell.Row
' LastUC = LastUCell.Column
'
' FirstUR = URng.Row
' FirstUC = URng.Column
' LastUR = URng.Rows.Count - URng.Row + 1
' LastUC = URng.Columns.Count - URng.Column + 1
'
' Set FirstUCell = .Cells(FirstUR, FirstUC)
' Set LastUCell = .Cells(LastUR, LastUC)
'
' Set FirstUCell = .Cells(URng.Row, URng.Column)
' Set FirstUCell = URng.Cells(1, 1)
' Set LastUCell = .Cells(URng.Rows.Count - URng.Row + 1, _
' URng.Columns.Count - URng.Column + 1)
' Set LastUCell = URng.Cells(URng.Rows.Count, URng.Columns.Count)
'
' Set URng = .Range(FirstUCell, LastUCell)
' Set URng = .Range(.Cells(FirstUR, FirstUC), .Cells(LastUR, LastUC))
' Set URng = .Range(FirstUCell.Address & ":" & LastUCell.Address)
' Various Resize and Offset possibilities
End With
End Sub