From the below VBA Code you will be able to find last cell in excel
Sub LastCell() 'Name of a Code
'Declaring the Variables
Dim LastCell As Integer 'Declaring the Variables
'Performing All VBA Action in the Active Sheet
With ActiveSheet
'Finding Last Row in a Sheet
LastCell = .Cells.SpecialCells(xlCellTypeLastCell).Row
'Displaying Message
MsgBox LastCell, , "LastRowinaSheet"
'Finding Last Column in a sheet
LastCell = .Cells.SpecialCells(xlCellTypeLastCell).Column
'Displaying Message
MsgBox LastCell, , "LastColumninaSheet"
'Finding Last Row in a Sigle Colum
LastCell = .Cells(.Cells.Rows.Count, "F").End(xlUp).Row
'Displaying Message
MsgBox LastCell, , "LastRowinaSingleColumn"
'Finding Last Column in a Single Row.
LastCell = .Cells(7, .Cells.Columns.Count).End(xlToLeft).Column
'Displaying Message
MsgBox LastCell, , "LastColumninaSingleRow"
'Finding Last Row using UsedRange
LastCell = .UsedRange.Rows(.UsedRange.Rows.Count).Row
'Displaying Message
MsgBox LastCell, , "LastRowUsingUsedRange"
'Finding Last Column using UsedRange
LastCell = .UsedRange.Columns(.UsedRange.Columns.Count).Column
'Displaying Message
MsgBox LastCell, , "LastColumnUsingUsedRange"
End With
End Sub
Sub LastCell() 'Name of a Code
'Declaring the Variables
Dim LastCell As Integer 'Declaring the Variables
'Performing All VBA Action in the Active Sheet
With ActiveSheet
'Finding Last Row in a Sheet
LastCell = .Cells.SpecialCells(xlCellTypeLastCell).Row
'Displaying Message
MsgBox LastCell, , "LastRowinaSheet"
'Finding Last Column in a sheet
LastCell = .Cells.SpecialCells(xlCellTypeLastCell).Column
'Displaying Message
MsgBox LastCell, , "LastColumninaSheet"
'Finding Last Row in a Sigle Colum
LastCell = .Cells(.Cells.Rows.Count, "F").End(xlUp).Row
'Displaying Message
MsgBox LastCell, , "LastRowinaSingleColumn"
'Finding Last Column in a Single Row.
LastCell = .Cells(7, .Cells.Columns.Count).End(xlToLeft).Column
'Displaying Message
MsgBox LastCell, , "LastColumninaSingleRow"
'Finding Last Row using UsedRange
LastCell = .UsedRange.Rows(.UsedRange.Rows.Count).Row
'Displaying Message
MsgBox LastCell, , "LastRowUsingUsedRange"
'Finding Last Column using UsedRange
LastCell = .UsedRange.Columns(.UsedRange.Columns.Count).Column
'Displaying Message
MsgBox LastCell, , "LastColumnUsingUsedRange"
End With
End Sub
Thank you Sir ji...
ReplyDeleteExcel keyboard shortcut that will speedup your work.
ReplyDelete10 basic excel tricks that will speed up your work.