Confusing Code

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
42,320
Office Version
365
Platform
Windows
Without knowing what your other code is, I've no idea.
 

Some videos you may like

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Kevin0427

Board Regular
Joined
Mar 31, 2016
Messages
69
Without knowing what your other code is, I've no idea.
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'Plan Rejected
If Target.Column = 12 Then
      Cancel = True
      Application.EnableEvents = False
      ActiveSheet.Unprotect Password:="test"
      Target.Offset(0, -6) = 0
      Target.Offset(0, 1) = Date + Time
      Target = "þ"
      Range("b" & Target.Row & ":bz" & Target.Row).Locked = True
      ActiveSheet.Protect Password:="test"
   End If
   Application.EnableEvents = True
'Invoice Sent
'First change
If Target.Column = 14 Then
    ActiveSheet.Unprotect Password:="test"
    If Target.Offset(0, 1) = "" Then
        Target.Offset(0, 1) = Date + Time
        Target = "þ"
'All other changes
    Else
        Target.Offset(0, 27) = Date + Time
        If Target = "¨" Then
            Target = "þ"
        Else
            Target = "¨"
        End If
    End If
ActiveSheet.Protect Password:="test"
End If
'Payment Received
'First change
If Target.Column = 16 Then
    ActiveSheet.Unprotect Password:="test"
    If Target.Offset(0, 1) = "" Then
        Target.Offset(0, 1) = Date + Time
        Target = "þ"
'All other changes
    Else
        Target.Offset(0, 26) = Date + Time
        If Target = "¨" Then
            Target = "þ"
        Else
            Target = "¨"
        End If
    End If
    ActiveSheet.Protect Password:="test"
End If
'Entered in GIS
'First change
If Target.Column = 19 Then
    ActiveSheet.Unprotect Password:="test"
    If Target.Offset(0, 26) = "" Then
        Target.Offset(0, 26) = Date + Time
        Target = "þ"
'All other changes
    Else
        Target.Offset(0, 27) = Date + Time
        If Target = "¨" Then
            Target = "þ"
        Else
            Target = "¨"
        End If
    End If
    ActiveSheet.Protect Password:="test"
End If
'Plans Scanned
'First change
If Target.Column = 20 Then
    ActiveSheet.Unprotect Password:="test"
    If Target.Offset(0, 27) = "" Then
        Target.Offset(0, 27) = Date + Time
        Target = "þ"
'All other changes
    Else
        Target.Offset(0, 28) = Date + Time
        If Target = "¨" Then
            Target = "þ"
        Else
            Target = "¨"
        End If
    End If
    ActiveSheet.Protect Password:="test"
End If
End Sub
Do I or should I be using a lot of subs instead of 1? Does that cause it? Sorry all my tabs and spacing is gone in the paste!!! Looks bad.
 
Last edited by a moderator:

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
42,320
Office Version
365
Platform
Windows
That code is not the problem. You have other event code such as a Worksheet_Change event
 

Kevin0427

Board Regular
Joined
Mar 31, 2016
Messages
69
That code is not the problem. You have other event code such as a Worksheet_Change event
This. And a few filters

Private Sub Worksheet_Change(ByVal Target As Range)

'Maximo Entered
ActiveSheet.Unprotect Password:="test"
If Target.Column = 18 Then
If Target.Offset(0, 25) = "" Then
Target.Offset(0, 25) = Date + Time
Else
Target.Offset(0, 26) = Date + Time
End If
End If
ActiveSheet.Protect Password:="test"
End Sub
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
42,320
Office Version
365
Platform
Windows
That code is relocking the sheet, which is causing you the problem.
Select this line in the doubleclick event
Code:
   If Target.Column = 12 Then
Then press F9, that line should get a brown highlight.
Then on the sheet doubleclick in col L, the above line of code should be highlighted, press F8 to step through the code & you can watch what happens.
 

Watch MrExcel Video

Forum statistics

Threads
1,101,746
Messages
5,482,608
Members
407,354
Latest member
Calvince

This Week's Hot Topics

  • Finding issue in If elseif else with For each Loop
    Finding issue in If elseif else with For each Loop I have tried this below code but i'm getting in Y column filled with W005. Colud you please...
  • MsgBox Error
    Hi Guys, I have the below error show up when i try and run my macro in File1 but works fine if i copy and paste the same code into file2. [ATTACH...
  • CELL FORMAT - IF CONDITION
    My Cell Format is [B]""0.00" Cr". [/B]But in the cell, it is showing 123.00 for editing. (123 is entry figure). (Data imported from other...
  • Show numbers nearly the same
    Is this possible. I have a number that can change very time eg 0.00001234 Then I have a lot of numbers 0.0000001, 0.0000002, 0.00000004...
  • Please i need your help to create formula
    I need a formula in cell B8 to do this >>if b1=1 then multiply ( cell b8) by 10% ,if b1=2 multiply by 20%,if=3 multiply by 30%. Thank you in...
  • Got error while adding column and filter
    Got error while adding column and filter In column Z has some like "Success" and "Error". I want to add column in AA if the Z cell value is...
Top