+ Reply to Thread
Results 1 to 7 of 7

Find/replace function in a protected sheet

  1. #1
    Registered User
    Join Date
    12-25-2019
    Location
    Delhi
    MS-Off Ver
    2019
    Posts
    4

    Find/replace function in a protected sheet

    I have a sheet as shown in the screenshot with a table made.

    It contains answers for questions. The grey cells indicate the question number. The white cells denote the answer number, e.g. 1,2,3 or 4.

    I will later on replace 1 with A, 2, with B, 3 with C, 4 with D.


    Now for testing purposes. I locked the question numbers, and protected my sheet. Then I entered few numbers in the cells for answers. Excel doesn't allow to do find/replace on a protected sheet.

    I want to do the find/replace such as, all '1' get replaced by A, '2' with B, so on and so forth. However, this find/replace shouldn't disturb the locked grey cells. How can I do this process?

    I am using Excel 2019 on Windows 10-64 bit.
    Attached Images Attached Images

  2. #2
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,078

    Re: Find/replace function in a protected sheet

    Hi there.

    A picture is worth 1,000 words. An Excel sheet is worth 1,000 pictures.

    Please read the yellow banner about sample worksheets, at the top of the screen. Act on its guidelines and post a SMALL sample sheet.
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: Lá fhéile Pádraig sona dhaoibh

  3. #3
    Registered User
    Join Date
    12-25-2019
    Location
    Delhi
    MS-Off Ver
    2019
    Posts
    4

    Re: Find/replace function in a protected sheet

    Yeah I just posted it. I had the screenshot ready. Only forgot to upload it before hitting the final button.

  4. #4
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,078

    Re: Find/replace function in a protected sheet

    Can we have a sheet, not a picture of one????

  5. #5
    Registered User
    Join Date
    12-25-2019
    Location
    Delhi
    MS-Off Ver
    2019
    Posts
    4

    Re: Find/replace function in a protected sheet

    Quote Originally Posted by Glenn Kennedy View Post
    Can we have a sheet, not a picture of one????
    Sure. Here it is.
    Attached Files Attached Files

  6. #6
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,078

    Re: Find/replace function in a protected sheet

    Well, you learn something new every day!! I hadn't realised that this was not possible. You could do it with VBA (but I couldn't - VBA is a dark art to me!!) so here is a formula based alternative.

    Your "numbers" on rows 2, 4, etc are text stored as numbers, so select them, row at a time, and convert to numbers

    With a lookup table of numbers and questions in R &S, use this, copied across and down:

    =IF(ISODD(ROW(F7)),F7,VLOOKUP(F7,$R:$S,2,FALSE))
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    12-25-2019
    Location
    Delhi
    MS-Off Ver
    2019
    Posts
    4

    Re: Find/replace function in a protected sheet

    Thanks. I'll try out your method for sure. Before you posted,while desperately searching for solution, I found a macro. Probably from here. A post made 14 years ago on this forum. I'm not allowed to post urls, so used a [dot] in place of actual dot.

    excelforum [dot] com/excel-general/474505-find-and-replace-within-unlocked-cells-in-a-protected-worksheet.html


    Sharing it here. I just blindly copy pasted it and used it. I am zero in programming.


    Option Explicit
    Sub testme()
    Dim fStr As String
    Dim tStr As String
    Dim myRng As Range
    Dim myUnlockedCells As Range
    Dim myCell As Range
    Dim wks As Worksheet
    Dim myPWD As String

    myPWD = "hi"

    Set wks = ActiveSheet

    With wks

    If .ProtectContents _
    Or .ProtectDrawingObjects _
    Or .ProtectScenarios Then
    'keep going
    Else
    MsgBox "Sheet is unprotected--just use Edit|Replace!"
    Exit Sub
    End If

    Set myRng = Nothing
    On Error Resume Next
    Set myRng = Intersect(Selection, .UsedRange)
    On Error GoTo 0

    If myRng Is Nothing Then
    MsgBox "Please select cells in the used range"
    Exit Sub
    End If

    For Each myCell In myRng.Cells
    If myCell.Locked = False Then
    If myUnlockedCells Is Nothing Then
    Set myUnlockedCells = myCell
    Else
    Set myUnlockedCells = Union(myUnlockedCells, myCell)
    End If
    End If
    Next myCell

    If myUnlockedCells Is Nothing Then
    MsgBox "No unlocked cells in the selected range"
    Exit Sub
    End If

    fStr = InputBox(Prompt:="Change what")
    If Trim(fStr) = "" Then
    Exit Sub
    End If

    tStr = InputBox(Prompt:="To what")
    If Trim(tStr) = "" Then
    Exit Sub
    End If

    .Unprotect Password:=myPWD

    If myUnlockedCells.Cells.Count = 1 Then
    Set myUnlockedCells _
    = Union(myUnlockedCells, _
    .Cells.SpecialCells(xlCellTypeLastCell).Offset(1, 1))
    End If

    On Error Resume Next
    myUnlockedCells.Cells.Replace what:=fStr, _
    replacement:=tStr, lookat:=xlPart, _
    searchorder:=xlByRows, MatchCase:=False
    If Err.Number <> 0 Then
    MsgBox "An error occurred during the mass change!"
    Err.Clear
    End If
    On Error Goto 0

    .Protect Password:=myPWD

    End With

    End Sub
    Last edited by archz2; 12-26-2019 at 11:30 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] Find & Replace within Unlocked Cells in a Protected Worksheet
    By DaveyC4S in forum Excel General
    Replies: 4
    Last Post: 06-28-2023, 11:28 PM
  2. VBA for Find & Replace function on protected sheet
    By esbencito in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-08-2018, 10:51 PM
  3. Multiple find and replace from Glossary sheet to the active sheet
    By Chandru71 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-22-2011, 12:34 PM
  4. Find/Replace on unlocked cells in protected sheet
    By deepu.gouwtham in forum Excel General
    Replies: 5
    Last Post: 06-12-2011, 07:34 PM
  5. Find/Replace on a protected sheet
    By LAF in forum Excel General
    Replies: 1
    Last Post: 07-10-2009, 09:32 PM
  6. Find/Replace on a protected sheet
    By LAF in forum Excel General
    Replies: 1
    Last Post: 06-23-2009, 07:39 AM
  7. [SOLVED] Replace on a password protected sheet
    By Matt in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 11-04-2005, 11: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