Results 1 to 13 of 13

Delete contents of protected cells using VBA

Threaded View

  1. #1
    Registered User
    Join Date
    02-08-2017
    Location
    Egypt
    MS-Off Ver
    2007
    Posts
    11

    Delete contents of protected cells using VBA

    I've created a user form template where the user will input in some fields and click a button "add to database" then the input will be moved to another worksheet and all the content in the "input" sheet will be cleared

    the problem is that when i try to lock any cell in the input sheet the clear content VBA will not work

    is there a way to run a clear content VBA on a locked cell at the end i need to lock cell D11 and cell D13 in the "Input" sheet
    Sub UpdateLogWorksheet()
    
    Dim historyWks As Worksheet
    Dim inputWks As Worksheet
    
    Dim nextRow As Long
    Dim oCol As Long
    
    Dim myRng As Range
    Dim myCopy As String
    Dim myCell As Range
    
    'cells to copy from Input sheet - some contain formulas
    myCopy = "D5,D7,D9,D11,D13"
    
    Set inputWks = Worksheets("Input")
    Set historyWks = Worksheets("Consolidate")
    
    With historyWks
        nextRow = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0).Row
    End With
    
    With inputWks
        Set myRng = .Range(myCopy)
    
        If Application.CountA(myRng) <> myRng.Cells.Count Then
            MsgBox "Please fill all data"
            Exit Sub
        End If
    End With
    
    With historyWks
        With .Cells(nextRow, "A")
            .Value = Now
            .NumberFormat = "mm/dd/yyyy hh:mm:ss"
        End With
        .Cells(nextRow, "B").Value = Application.UserName
        oCol = 3
        For Each myCell In myRng.Cells
            historyWks.Cells(nextRow, oCol).Value = myCell.Value
            oCol = oCol + 1
        Next myCell
    End With
    
    'clear input cells that contain constants
    With inputWks
      On Error Resume Next
         With .Range(myCopy).Cells.SpecialCells(xlCellTypeConstants)
              .ClearContents
              Application.GoTo .Cells(1) ', Scroll:=True
         End With
      On Error GoTo 0
    End With
    End Sub
    Last edited by FDibbins; 02-09-2017 at 03:08 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Need to delete rows in sheet with protected cells
    By Timmy2tone in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-29-2014, 03:41 PM
  2. Delete only some of a cells contents
    By Dendrinos2 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-11-2014, 06:16 AM
  3. [SOLVED] Delete special cells & protected workbook
    By Lukael in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-30-2014, 10:11 AM
  4. Want to delete all non-protected cells in a worksheet
    By BillDoor in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-14-2013, 11:31 AM
  5. Delete rows in a protected sheet with protected cells
    By Maranwe in forum Excel General
    Replies: 7
    Last Post: 10-31-2011, 08:12 AM
  6. Add/Delete Rows with Protected Cells
    By NoiCe in forum Excel General
    Replies: 1
    Last Post: 10-22-2009, 02:59 AM
  7. [SOLVED] Macro to delete row with protected cells
    By Turboj in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-21-2006, 12:45 AM

Tags for this Thread

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