How To clear cell if cell another cell has "No.

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,036
Hi thanks. I have x2 private subs with the same name though. How would I add to the one I already have?
 

Some videos you may like

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
35,678
Office Version
365
Platform
Windows
What's the code you already have?
 

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,036
hi the other code is
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim Changed As Range, Rw As Range

  Set Changed = Intersect(Target, Union(Range("H:H"), Range("H:H")))
  If Not Changed Is Nothing Then
    Application.EnableEvents = False
    For Each Rw In Changed.Rows
      Cells(Rw.Row, "Q").Value = Environ("Username")
      Cells(Rw.Row, "R").Value = Now
      Cells(Rw.Row, "R").NumberFormat = "dd/mm/yyyy hh:mm"
    Next Rw
    Application.EnableEvents = True
  End If
  
End Sub
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
35,678
Office Version
365
Platform
Windows
try
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   Dim Rw As Range
   
   If Not Intersect(Target, Range("H:H")) Is Nothing Then
      Application.EnableEvents = False
      For Each Rw In Target.Rows
         Cells(Rw.Row, "Q").Value = Environ("Username")
         Cells(Rw.Row, "R").Value = Now
         Cells(Rw.Row, "R").NumberFormat = "dd/mm/yyyy hh:mm"
      Next Rw
   ElseIf Target.Address(0, 0) = "AA5" Then
      If LCase(Target.Value) = "cancel all" Then
         Range("T5").Clear
      ElseIf LCase(Target.Value) = "cancel 1" Then
         Range("T5").Value = Range("T5").Value - 1
      End If
   End If
   Application.EnableEvents = True
End Sub
 

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,036
thank you I will try that, please can you advise for future reference if I come across this again and I need to add extra to this sub how will I do it?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
35,678
Office Version
365
Platform
Windows
In much the same way as i did above. ;)
 

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,036
hi thank you, I have just changed the code a little by extending the range but it came back with an error, it didnt like the s5:v5 range as want it to check 5 cells as a number will be in one of those, can you help please?
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   Dim Rw As Range
   
   If Not Intersect(Target, Range("H:H")) Is Nothing Then
      Application.EnableEvents = False
      For Each Rw In Target.Rows
         Cells(Rw.Row, "Q").Value = Environ("Username")
         Cells(Rw.Row, "R").Value = Now
         Cells(Rw.Row, "R").NumberFormat = "dd/mm/yyyy hh:mm"
      Next Rw
   ElseIf Target.Address(0, 0) = "AA5" Then
      If LCase(Target.Value) = "cancel all" Then
         Range("S5:V5").Clear
      ElseIf LCase(Target.Value) = "cancel 1" Then
         Range("S5:V5").Value = Range("S5:V5").Value - 1
      End If
   End If
   Application.EnableEvents = True
End Sub
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
35,678
Office Version
365
Platform
Windows
Is this the last change that you are going to request, before I re-write it again?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
35,678
Office Version
365
Platform
Windows
Do you want to change the value in all cells from S5 to V5?
 

Forum statistics

Threads
1,089,600
Messages
5,409,213
Members
403,256
Latest member
Viq

This Week's Hot Topics

  • help please
    SORRY NOT ANY GOOD AT EXCEL SO HELP WOULD BE MUCH APPRECIATED this formula is in a sheet called ignore...
  • two formulas needed
    Hello, I'll try my best to explain this: First formula needed in Sheet1 cell A2: If Sheet1 cell B2 = Sheet2 cell B2 then return a 1. If not then...
  • Dynamic Counts
    Good afternoon, we are tidying up some data & the data seems to be growing quicker than we are tidying it up! What we confirm (by reviewing it...
  • Help Excel formula eliminate duplicate values and keep only 2 identical rows.
    as picture below column A has a duplicate value. but the values are not the same as the rule. sometimes 4 rows, sometimes 10 rows or 7 or 9...
  • Macro Compile Error Sub or Function not defined
    Hello, I am trying to run macros from a validation list, all macros have been created and run perfectly on there own but I'm getting a compile...
  • Last row combined with Current Region VBA
    I'm generally happy finding the last row of data through something like Lastrow = Cells(Rows.Count, "D").End(xlUp) but I don't always receive data...
Top