+ Reply to Thread
Results 1 to 8 of 8

Userform only works on sheet 2

  1. #1
    Registered User
    Join Date
    02-26-2020
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    29

    Userform only works on sheet 2

    Hi All,

    Still quite new to VBA but I've put together a little application to help my team try and manage the assets we have. Each with its own asset ID.

    I wanted the application to be able to allow the team to book in and out assets and for it to be recorded simultaneously on an audit log, and for it to be able to update the asset register (sheet 2) with the name of the person who its assigned to and update the status from "available" to "unavailable" etc.

    The problem I have is that the userform only seems to work when I press "play" from the vba editor and if sheet 2 is open! I cant seem to figure out why it wont run correctly with sheet 1 open.

    Any help would be amazing.

    Thanks in advance.

    I've tried to add the workbook to this thread post. Bare with me if it hasnt worked.
    Attached Files Attached Files

  2. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Userform only works on sheet 2

    I don't know what triggers the error (is it an error? or just doesn't function properly), but check your range references... for example in CommandButton7_Click you have
    Please Login or Register  to view this content.
    which will use A:A on the active sheet, and I assume lines like that are your problem (commandbutton8 has the same, didn't check ALL lines in the code)
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  3. #3
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,304

    Re: Userform only works on sheet 2

    ws2 had not been assigned early enough

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    02-26-2020
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    29

    Re: Userform only works on sheet 2

    Thanks for this.
    So I've updated the code with your additions and unfortunately it still doesn't have the desired outcome.

    There is no error produced. It just doesn't function properly. The "Audit Log" sheet updates fine and as expected, but the "Asset Register Worksheet" remains unchanged.

    All worksheets will also remain locked for editing by a password.

    Any further suggestions? Its been bugging me for so long! Desperate to fix!

  5. #5
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Userform only works on sheet 2

    Did you also check my reply? Those "Set Found1 = Range("A:A").Find(str1)" statements would benefit from including a worksheet reference ... Set Found1 = Worksheet.Range("A:A").Find(str1) (where Worksheet would be a worksheet object like you have in other parts of the code.)

  6. #6
    Registered User
    Join Date
    02-26-2020
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    29

    Re: Userform only works on sheet 2

    AH!! My brain thought I had done what you suggested but I had, infact not... It works! Genius!

    Thank you so much both of you!

  7. #7
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Userform only works on sheet 2

    Glad to hear it!
    Thanks for the feedback, rep, and marking the thread as solved

  8. #8
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,304

    Re: Userform only works on sheet 2

    I found despite setting the worksheet the find was not stable.
    As you have already loaded the combobox you know the item exists.
    Therefore use the combobox listindex to ID the row.
    I have altered the attached code to suit, it is several lines shorter and is direct with no need for searches.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Userform VBA only works when used on particular pages?
    By matrixpom in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-10-2020, 11:07 PM
  2. Replies: 1
    Last Post: 07-02-2018, 07:32 PM
  3. [SOLVED] Userform Initialize (sometimes works, sometimes don't!)
    By Rajeshkumar R in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-18-2017, 01:57 PM
  4. [SOLVED] Userform initialize (sometimes works, sometimes don't!)
    By pepito_child in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-04-2016, 02:10 AM
  5. Function works with module but not in USERFORM..
    By karthik013 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-15-2013, 11:53 AM
  6. Userform works only in Local Computer.
    By ebin charles in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-27-2011, 12:23 PM
  7. userform only works on my PC
    By Canuckbulldog in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-22-2007, 08:40 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1