Want this code to work if any part of answer appears (Joe, Analyst, not just Analyst)

Kusaywa

Board Regular
Joined
Aug 26, 2016
Messages
123
I have a formula that pulls from a list of employees via their ID Number.
Employees that are Analysts have Analyst next to their name (Joe Jones, Analyst).
This code only works if the answer is "Analyst"
How can I get it to work with any employee that has Analyst in their Name?
This way I don't have to change the code for every employee.
Thanks

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Set MyPlage = Range("A2:D4800")
      
    For Each cell In MyPlage
      ActiveSheet.Unprotect ("peteamy")
        Select Case cell.Value
          
         Case Is = "Analyst"
            cell.EntireRow.Font.ColorIndex = 3
          ActiveSheet.Protect ("peteamy")
        End Select
End Sub
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
crosspost

Read this to understand crossposting, and then please edit your first post to include links to any and all cross-posts in any other forums (not just this site).
 
Last edited:
Upvote 0
Cross-posted here: http://www.ozgrid.com/forum/showthread.php?t=201102

While we do not prohibit Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule #13 here: Forum Rules).

This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.

For a more complete explanation on cross-posting, see here: Excelguru Help Site - A message to forum cross posters).
 
Last edited:
Upvote 0
Try this.

Howard

Code:
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)

Dim MyPlage As Range, c As Range
Set MyPlage = Range("A2:D4800")
'ActiveSheet.Unprotect ("peteamy")
      
   For Each c In MyPlage
      
     If InStr(c, "Analyst") > 0 Then
      c.EntireRow.Font.ColorIndex = 3
     End If
   
      Next
      
'ActiveSheet.Protect ("peteamy")
End Sub
 
Upvote 0
Are you using c or Cell as the Dimmed Range.

Maybe post the full code you are using, if not exactly as the one I posted.

Howard
 
Upvote 0
I replaced my code with yours minus the option explicit and got the error. Does option explicit matter? In mine it uses cell but it's not "my" code, I found it and applied it. Mine does use cell, while yours uses c. I tried replacing c with cell and got the same error.
 
Upvote 0
Here's my complete code.
You can see, I've got a lot going on.
But it all works, believe it or not.
Just trying to get the "name" thing worked out.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Set MyPlage = Range("A2:D4800")
      
    For Each cell In MyPlage
      ActiveSheet.Unprotect ("peteamy")
        Select Case cell.Value
          
         Case Is = "Peter"
            cell.EntireRow.Font.ColorIndex = 3
          ActiveSheet.Protect ("peteamy")
        End Select
      Next
      
      
Dim rw As Long
rw = Target.Row
     If Range("B" & rw).Value <> "" Then
        ActiveSheet.Unprotect ("peteamy")
        Range("D" & rw).Locked = False
        ActiveSheet.Protect ("peteamy")
        'Remove locked property if B3's value is anything else or is deleted.
     Else
        ActiveSheet.Unprotect ("peteamy")
        Range("D" & rw).Locked = True
        'Optional, reprotect sheet
        ActiveSheet.Protect ("peteamy")
     End If

Dim Answ As String
Application.ScreenUpdating = False
Answ = MsgBox("Do you wish to confirm entry of this data?", vbOKCancel, "Confirm Change")
  If Answ <> vbOK Then
  Application.EnableEvents = False
  Target.ClearContents 'clear contents if cancel is pressed
  Application.EnableEvents = True
  Exit Sub
  End If
ActiveSheet.Unprotect "peteamy"
Target.Locked = True
ActiveSheet.Protect Password:="peteamy", DrawingObjects:=True, Contents:=True, Scenarios:=True
Application.ScreenUpdating = True
 
 
Dim Sht As Worksheet
  If Target.Address = "$D$4800" Then
  
  Dim MyPath As String
    Dim MyFileName As String
    
    Application.DisplayAlerts = False
    MyPath = ThisWorkbook.Path
    MyFileName = Left(ThisWorkbook.Name, (InStrRev(ThisWorkbook.Name, ".", -1, vbTextCompare) - 1)) & (" ") & Format(Now, "dd-mm-yyyy hh-mm")
    
    If Not Right(MyPath, 1) = "\" Then MyPath = MyPath & "\"
    If Not Right(MyFileName, 4) = ".xlsx" Then MyFileName = MyFileName & ".xlsx"
    
    ActiveSheet.Copy
    
    With ActiveWorkbook
    
        .SaveAs Filename:= _
            MyPath & MyFileName, _
            CreateBackup:=False
            
        .Close False
        
        Application.DisplayAlerts = True
        
        End With
  
  ActiveWorkbook.Unprotect "peteamy"
  Application.ScreenUpdating = False
  Sheets("Sheet2").Visible = True
    'Replace "Sheet1" with the name of the sheet to be copied.
    ActiveWorkbook.Sheets("Sheet2").Copy _
       after:=ActiveWorkbook.Sheets(ActiveWorkbook.Sheets.Count)
       Sheets("Sheet2").Visible = xlSheetVeryHidden
       
       
       Application.DisplayAlerts = False
On Error Resume Next
ActiveSheet.Previous.Previous.Delete
ActiveWorkbook.Protect "peteamy"
   End If
   
   On Error Resume Next
    Application.EnableEvents = False
    If Not Target.Cells.CountLarge > 1 Then
        
        If Not Intersect(Target, Columns(4)) Is Nothing Then
            Target.Offset(1, -2).Select
        End If
    End If
Letscontinue:
    Application.EnableEvents = True
    Exit Sub
Whoa:
    MsgBox Err.Description
    Resume Letscontinue
       
       End Sub
 
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
 CurrentRow = ActiveCell.Row
If CurrentRow = 1 Then Exit Sub
 CurrentCol = ActiveCell.Column
If Cells(CurrentRow - 1, CurrentCol).Value = 0 Then
 MsgBox ("Please Do Not Skip Rows")
 ActiveCell.Offset(-1, 0).Activate
End If
Dim MyRange As Range, lr As Long
lr = Cells(Rows.Count, "B").End(xlUp).Row
Set MyRange = Range("B2:B" & lr)
For Each cell In MyRange
If cell.Value <> "" And cell.Offset(0, 2).Value = "" Then
MsgBox "Your ID Number is Required"
Application.EnableEvents = False
cell.Offset(0, 2).Select
Application.EnableEvents = True
Exit Sub
End If
Next cell
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,865
Messages
6,121,988
Members
449,060
Latest member
mtsheetz

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top