Skip to main content

Find the Last Row, Column, in Excel using VBA





It will help you to find out last row count, column count then you can easily loop through your data according to requirement. Let's suppose your Excel contains blank cells then there is a different Code for that, you can easily use this in Visual Basic of Excel and Execute that in UiPath using activity Execute Macro.

***LastRow****

Range("A1").Select / Cells(1,1).Select
lastrow = Range(Selection, ActiveCell.End(xlDown)).Rows.Count
lastrow = ActiveSheet.UsedRange.Rows.Count

***LastColumn***

Range("A1").Select / Cells(1,1).Select
lastcol = Range(ActiveCell.End(xlToRight), Selection).Columns.Count
lastcol = ActiveSheet.UsedRange.Columns.Count

***LastRow With Spaces***

xIndex = Application.ActiveCell.Column
xRowIndex = Application.ActiveSheet.Cells(Rows.Count, xIndex).End(xlUp).Row
Range(Cells(1, xIndex), Cells(xRowIndex, xIndex)).Select
lastrow = Selection.Count

***LastCol With Spaces***

xIndex = Application.ActiveCell.Row
xColIndex = Application.ActiveSheet.Cells(xIndex, Columns.Count).End(xlToLeft).Column
Range(Cells(xIndex, 1), Cells(xIndex, xColIndex)).Select
colCount = Selection.Count

   

Comments

  1. very nice and provide me informative content thanks for sharing for more information Looking for the best Create new worksheet

    ReplyDelete

Post a Comment