+ Reply to Thread
Results 1 to 2 of 2

How to lock cells in and let Macros ovverwrite anyway

Hybrid View

  1. #1
    Registered User
    Join Date
    07-13-2016
    Location
    Stockholm
    MS-Off Ver
    2013
    Posts
    27

    How to lock cells in and let Macros ovverwrite anyway

    I want to lock certain cells so users of the woorkbook wont be able to make changes but at the same time I want macros to be able to make changes.

    For instance I want to lock range "A1" so no user can type things in A1. But the following macro should be able to write and overwrtite in cell A1

    Sub Macro1()
    a = Date
    Range("A1") = a
    End Sub

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,525

    Re: How to lock cells in and let Macros ovverwrite anyway

    You need to unprotect the sheet first
    Sub Button1_Click()
        Dim sh As Worksheet
        Set sh = Sheets("Sheet1")
        sh.Unprotect
        Range("A1") = Date
        sh.Protect
    End Sub
    Lots of example to unprotect the sheet with a password as well

    activesheet.unprotect "password" 
    sh.unprotect "password"
    Last edited by davesexcel; 08-24-2017 at 10:46 AM.

+ 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] Lock rows unless they are hidden or unhidden by macros?
    By dgibney in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-15-2014, 04:06 PM
  2. Are there any macros to lock a colum after one pane had been freezed?
    By pejoi in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-08-2012, 10:48 AM
  3. Replies: 2
    Last Post: 02-22-2012, 10:10 AM
  4. Can I lock cells or do I have to lock the worksheet?
    By jmbtexas in forum Excel General
    Replies: 4
    Last Post: 11-11-2008, 02:26 PM
  5. [SOLVED] How can I lock worksheets while macros can still enter into them?
    By enginguven in forum Excel General
    Replies: 3
    Last Post: 01-11-2006, 09:00 PM
  6. [SOLVED] How can I lock worksheets while still allowing macros to operate?
    By enginguven in forum Excel General
    Replies: 2
    Last Post: 01-09-2006, 06:10 PM
  7. [SOLVED] How can I lock worksheets while still allowing macros to operate?
    By enginguven in forum Excel General
    Replies: 1
    Last Post: 01-09-2006, 05:50 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