finding last cell of data

  • Thread starter Thread starter mark kubicki
  • Start date Start date
M

mark kubicki

any suggestions about why this is not working;
....it always finds the last fellof data on th e sheet as "A1" (it is not)

'determine last row of data
Set foundcell = Cells.Find("*", Range("A1"), xlValues, xlPart, xlByRows,
xlPrevious)
If foundcell Is Nothing = 0 Then
lDataRow = 1
lDataCell = Range("A1").Address
Else
lDataRow = foundcell.Row
lDataCell = foundcell
End If


thanks in advance,
mark
 
I use this to give the intersect cell of the last used Row and last
used Column:
Function FindLastCell() As Range
Dim LastColumn As Integer
Dim LastRow As Long
Dim LastCell As Range
If WorksheetFunction.CountA(Cells) > 0 Then
'Search for any entry, by searching backwards by Rows.
LastRow = Cells.Find(What:="*", After:=[A1], _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
'Search for any entry, by searching backwards by Columns.
LastColumn = Cells.Find(What:="*", After:=[A1], _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Column
Set FindLastCell = Cells(LastRow, LastColumn)
Else
Set FindLastCell = Range("A1")
End If
End Function

Charles
 
I would try

Sub abc()
Set foundcell = Cells.Find("*", Range("A1"), xlFormulas, xlPart,
xlByRows, xlPrevious)

If foundcell Is Nothing Then
lDataRow = 1
lDataCell = Range("A1").Address
Else
lDataRow = foundcell.Row
lDataCell = foundcell
End If
Debug.Print lDataRow, lDateCell
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top