Regarding the identification of the last row or column of a spreadsheet, is it dangerous to use the single line below instead of the lengthy function lastrowN below it?
My mind prefers simplicity but if it creates problems....
lastrow = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row
Function lastrowN()
' Returns last row1 in activesheet
Dim ExcelLastCell As Range
Dim row1 As Double, row2 As Double, rowmove As Double
' ExcelLastCell is what Excel thinks is the last cell
Set ExcelLastCell = ActiveSheet.Cells.SpecialCells(xlLastCell)
' Determine the last row1 with data in it
row1 = ExcelLastCell.Row
rowmove = Int(row1 / 2 - 1) + 1
row2 = row1 - rowmove
Do While Application.CountA(Range(Cells(row1, 1), Cells(row1, 256))) = 0 _
And row1 <> 1
'Application.StatusBar = Row1
If Application.CountA(Range(Cells(row1, 1), Cells(row2, 256))) = 0 Then
rowmove = Int(rowmove / 2 - 1) + 1
row1 = row2
If rowmove < 1 Then rowmove = 1
row2 = row2 - rowmove
If row2 < 1 Then row2 = 1
Else
rowmove = Int(rowmove / 2 - 1) + 1
If rowmove < 1 Then rowmove = 1
row2 = row1 - rowmove
row1 = row1 - 1
End If
Loop
lastrowN = row1
End Function
My mind prefers simplicity but if it creates problems....
lastrow = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row
Function lastrowN()
' Returns last row1 in activesheet
Dim ExcelLastCell As Range
Dim row1 As Double, row2 As Double, rowmove As Double
' ExcelLastCell is what Excel thinks is the last cell
Set ExcelLastCell = ActiveSheet.Cells.SpecialCells(xlLastCell)
' Determine the last row1 with data in it
row1 = ExcelLastCell.Row
rowmove = Int(row1 / 2 - 1) + 1
row2 = row1 - rowmove
Do While Application.CountA(Range(Cells(row1, 1), Cells(row1, 256))) = 0 _
And row1 <> 1
'Application.StatusBar = Row1
If Application.CountA(Range(Cells(row1, 1), Cells(row2, 256))) = 0 Then
rowmove = Int(rowmove / 2 - 1) + 1
row1 = row2
If rowmove < 1 Then rowmove = 1
row2 = row2 - rowmove
If row2 < 1 Then row2 = 1
Else
rowmove = Int(rowmove / 2 - 1) + 1
If rowmove < 1 Then rowmove = 1
row2 = row1 - rowmove
row1 = row1 - 1
End If
Loop
lastrowN = row1
End Function