Create a form to input data whihc can then be a shared worksheet

  • Hi ihave been following a youtube video to create a form to input data. once this was completed I was hoping I could share this only issue I have is when I click my save button I get message:


    Run-time '91':


    Object variable or WIth variable not set


    when I click debug it highlights this section:


    Code
    'find first empty row in database
    iRow = ws.Cells.Find(What:="*", _
                             SearchOrder:=xlRows, _
                             SearchDirection:=xlPrevious, _
                             LookIn:=xlValues).Row + 1


    Can you advise me where I am going wrong I have also included below the full code



    Thanks

  • Re: Create a form to input data whihc can then be a shared worksheet


    Hi Aneesmazir,


    Welcome to Ozgrid!!


    That error is usually the result of there being no data on the sheet. This should do the job:


    Code
    'Find first empty row in database
        On Error Resume Next 'Account for there being no data on the 'ws' tab
            iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
            If iRow = 0 Then
                iRow = 2 'Default row number if there's no data on the 'ws' tab. Change to suit.
            End If
        On Error GoTo 0


    Please also wrap any code you post with the appropriate tags as I have done. I have done it this time for you.


    Regards,


    Robert

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!