Home » excel » vba – Class member function throwing error on simple range function

vba – Class member function throwing error on simple range function

Posted by: admin May 14, 2020 Leave a comment

Questions:

so I have a VBA function that keeps throwing the error ‘Application-defined or object-defined error’ and I can’t figure out why. The function is meant to copy a block of cells from one sheet to another. I’ve used code like this in other areas with no problems, so don’t understand why this isn’t working.

    'update on main screen
    Public Sub mainImageUpdate(roomstring)
        set yoffset = Worksheets("Source").Range("A:A").Find(roomstring, , xlValues, xlWhole).Row
        Worksheets("Source").Range("B1:AB10").Offset(yoffset - 1, 0).Copy _
            Destination:=Worksheets("Main").Range("O5")
    End Sub
How to&Answers:
Public Sub mainImageUpdate(roomstring)
Dim Y as range
set y  = Worksheets("Source").Range("A:A").Find(roomstring, , xlValues, xlWhole)  'look for it
if not y is nothing then  'did you find it?
    Worksheets("Source").Range("B10:AB10").Offset(y.row - 1, 0).Copy _
        Destination:=Worksheets("Main").Range("O5")
else
      'do something?
end if
End Sub