+ Reply to Thread
Results 1 to 16 of 16

Prevent manual user input but not Macro

Hybrid View

  1. #1
    Registered User
    Join Date
    03-02-2018
    Location
    Nottm
    MS-Off Ver
    365
    Posts
    72

    Prevent manual user input but not Macro

    Hi, new to the forum, looking forward to learning some great stuff.

    I have a spreadsheet where I need to stop manual user input into some cells, but still allow a macro to fill the cells, is that possible?
    Thank you.

  2. #2
    Valued Forum Contributor ranman256's Avatar
    Join Date
    07-29-2012
    Location
    Kentucky
    MS-Off Ver
    Excel 2003
    Posts
    1,190

    Re: Prevent manual user input but not Macro

    Lock the cells needed.(default i believe) and unlock the ones user can enter data.

    Set a password on the sheet.
    Let the macro unlock, then write data.
    it its a formula, lock that cell too.

    Public Const kPASS = "bob"
    
    Sub MyMacro1()
        ActiveSheet.Unprotect Password:=kPASS
          Range("C2").Value = Range("A2").Value / Range("b2").Value
        ActiveSheet.Protect Password:=kPASS, DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowSorting:=True, AllowFiltering:=True, AllowUsingPivotTables:=True
    End Sub

  3. #3
    Registered User
    Join Date
    03-02-2018
    Location
    Nottm
    MS-Off Ver
    365
    Posts
    72

    Re: Prevent manual user input but not Macro

    Sorry, I would need more instruction than that. I know how to go in and edit modules at a beginner level, but where would I enter that information? There are currently 4 modules in the spreadsheet now. I was not the person that created this spreadsheet.

  4. #4
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,947

    Re: Prevent manual user input but not Macro

    If you need that level of help then it's probably easier if you attach a desensitized version of your workbook and explain exactly what it is you need.

    BSB

  5. #5
    Registered User
    Join Date
    03-02-2018
    Location
    Nottm
    MS-Off Ver
    365
    Posts
    72

    Re: Prevent manual user input but not Macro

    I want users to open the spreadsheet without a password, be able to manually input into some cells and not other. I want to force the user to use the macro to insert their data into certain cells.

    I just unlocked all cells, then made sure only the cells I want protecting were locked. Then I protected the sheet with a password. That worked in that, I could no longer manually enter data into those cells, but this didn't allow the macro to input those cells either.

  6. #6
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,947

    Re: Prevent manual user input but not Macro

    Hi and welcome.

    Yes it is indeed possible. You can protect the worksheet and set the "UserInterfaceOnly" setting to True. That way the VBA can interact with the sheet but the user cannot.

    See the link below for more information on its usage
    http://www.cpearson.com/excel/Protection.aspx

    BSB

  7. #7
    Registered User
    Join Date
    03-02-2018
    Location
    Nottm
    MS-Off Ver
    365
    Posts
    72

    Re: Prevent manual user input but not Macro

    Okay, thanks for your help.

  8. #8
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,947

    Re: Prevent manual user input but not Macro

    Because you need to protect the sheet, in VBA, with the UserInterfaceOnly set to True. Just protecting the sheet via the user interface stops the macros being able to make changes too.

    Something like this (adapt sheet names to suit) in your ThisWorkbook module will do the trick.
    Private Sub Workbook_Open()
        Worksheets("Sheet1").Protect UserInterfaceOnly:=True
    End Sub
    BSB

  9. #9
    Registered User
    Join Date
    03-02-2018
    Location
    Nottm
    MS-Off Ver
    365
    Posts
    72

    Re: Prevent manual user input but not Macro

    That did the trick, thank you so much!!

  10. #10
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,947

    Re: Prevent manual user input but not Macro

    Happy to help

    Don't forget to mark the thread as SOLVED if you're happy you have a working solution.

    BSB

  11. #11
    Registered User
    Join Date
    03-02-2018
    Location
    Nottm
    MS-Off Ver
    365
    Posts
    72

    Re: Prevent manual user input but not Macro

    Will do, but one more quick question. How do I get it to run that macro automatically when the file is open? Currently, I'm having to manually run it.

  12. #12
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,947

    Re: Prevent manual user input but not Macro

    It's a "workbook open event", therefore so long as it's in the workbook module (not a standard, class or sheet level module) then it will run when you open the workbook (so long as macros are enabled!)

    BSB

  13. #13
    Registered User
    Join Date
    03-02-2018
    Location
    Nottm
    MS-Off Ver
    365
    Posts
    72

    Re: Prevent manual user input but not Macro

    Here's what it looks like. I entered your code in module 5
    Capture.PNG

  14. #14
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,947

    Re: Prevent manual user input but not Macro

    Look a few lines up from there. See where it says "ThisWorkbook" just below "Sheet5 (Drop Downs)" and just above "Modules"?
    Cut the code from Module 5, double click where it says "ThisWorkbook" and paste it in there. That way it will fire whenever you open the workbook.

    BSB

  15. #15
    Registered User
    Join Date
    03-02-2018
    Location
    Nottm
    MS-Off Ver
    365
    Posts
    72

    Re: Prevent manual user input but not Macro

    Fantastic, thank you for your patience with the beginner newbie.

  16. #16
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,947

    Re: Prevent manual user input but not Macro

    No problem at all. We all started somewhere

    BSB

+ 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. user defined macro to replace certain characters in a string based on user input
    By whatappears in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-17-2012, 06:25 PM
  2. Prevent User Input into ActiveX text box
    By g8r777 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-11-2012, 03:03 PM
  3. Changing code from Manual input to Calculated input
    By Gertheking in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-16-2012, 11:41 AM
  4. Automatic Formula Input Based on User Input Using a Macro
    By Drayloc in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-03-2012, 12:10 PM
  5. Run Macro on cell change from streaming data (not manual user input)
    By Test123Test in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-20-2012, 12:58 PM
  6. Pause macro for user input then search for user's answer across multiple sheets
    By sassy2 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-04-2009, 03:55 AM
  7. prevent user moving out of textbox if input is bad
    By johncassell in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-08-2006, 09:23 AM
  8. Prevent a user from running a macro
    By vbace2 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-27-2006, 11:28 PM

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