'LastRow' Function not working

R

Randy Reese

This is basically what I have. It was working at one time. Not sure why now.


____________________________________________________

Private Sub btnProcess_Click()
btnProcess.Enabled = False

Call test1

End Sub
____________________________________________________
Function LastRow(sh As Worksheet)
On Error Resume Next
LastRow = sh.Cells.Find(What:="*", _
after:=sh.Range("B0"), _
lookat:=xlPart, _
LookIn:=xlValues, _
searchorder:=xlByRows, _
searchdirection:=xlPrevious, _
MatchCase:=False).Row

On Error GoTo 0
End Function
___________________________________________________

Public Sub ProcessSingle1(ws As Worksheet, WS2 As Worksheet, Str As String)

Dim LRow As Long
LRow = LastRow(WS2)
End Sub
___________________________________________________

Sub test1()
ActiveCell.Activate
Dim ws As Worksheet
Dim WS2 As Worksheet
Dim Str As String



'UNSCHEDULED
Set ws = Sheets("Unsc.")
Set WS2 = Sheets("Print281")
Str = "81"
Call ProcessSingle(ws, WS2, Str)

End Sub
___________________________________________________
 
G

Guest

Hi,
To look for the last row of data in a column, say column B of sheet Wsh
LastRow = Wsh.Range("B65536").End(xlup).Row
It assumes data stop before row 65536.
It is the same as manually selecting B65536 and doing a CTRL+ArrowKeyUP
 
R

Rob van Gelder

Range("B0") is not a valid cell reference.
It will have to be a named range if it's going to work.
 
J

John Green

This method for finding the last row containing data should start its search
in the A1 cell.

What does B0 represent. Is it a name? If so, it should refer to A1.

Try replacing B0 with A1.

John Green
 

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

Top