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

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,036
hi I want it to look for the number in s5, t5, u5, v5 as it will be in one of these cells, then update the cell which has the number in, thank you :)
 

Some videos you may like

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
35,673
Office Version
365
Platform
Windows
OK, 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("S5:V5").Clear
      ElseIf LCase(Target.Value) = "cancel 1" Then
         With Range("S5:V5")
            .Value = Evaluate("if(" & .Address & "<>""""," & .Address & "-1,"""")")
         End With
      End If
   End If
   Application.EnableEvents = True
End Sub
 

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,036
Thank you for the help. What does the evaluate and address line do please? I tried the s5:v5 before but didn't work but i see you added a new line. Thank you again :)
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
35,673
Office Version
365
Platform
Windows
Glad to help & thanks for the feedback.

That line simply checks if the cells in the range have a value & if so subtract 1 from them, otherwise returns ""
 

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,036
that is great thankyou for the education and help much appreciated
 

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,036
hi good morning, sorry just one more question, I have tried duplicating the code to add another cell (the one below) please see below what I have done, but I am getting an error, please can you advise what I have done wrong? thank you, I did say no more questions from me thinking I would be okay :)
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
         With Range("S5:V5")
            .Value = Evaluate("if(" & .Address & "<>""""," & .Address & "-1,"""")")
            Next Rw
             ElseIf Target.Address(0, 0) = "AA6" Then
      If LCase(Target.Value) = "cancel all" Then
         Range("S6:V6").Clear
      ElseIf LCase(Target.Value) = "cancel 1" Then
         With Range("S6:V6")
            .Value = Evaluate("if(" & .Address & "<>""""," & .Address & "-1,"""")")
         End With
      End If
   End If
   Application.EnableEvents = True
End Sub
 

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,036
HI is is the new bit I added trying to copy what was for the previous cells but just changing the number to the next cell below ie AA6 and S6:V6 thought it would be simple to add the new lines but getting the error :(
Code:
            Next Rw
             ElseIf Target.Address(0, 0) = "AA6" Then
      If LCase(Target.Value) = "cancel all" Then
         Range("S6:V6").Clear
      ElseIf LCase(Target.Value) = "cancel 1" Then
         With Range("S6:V6")
            .Value = Evaluate("if(" & .Address & "<>""""," & .Address & "-1,"""")")
 

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,036
hello, hope you can help :), you have been great with all the advice already, I did think this would be easy to do and just paste previous code with the section and paste underneath and just change the cells range for example aa5 t aa6 and s5:v5 to s6:v6, do I need to break it up somehow?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
35,673
Office Version
365
Platform
Windows
Try
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   Dim Rw As Range
   
   Application.EnableEvents = False
   If Not Intersect(Target, Range("H:H")) Is Nothing Then
      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 Not Intersect(Target, Range("AA5:AA6")) Is Nothing Then
      If LCase(Target.Value) = "cancel all" Then
         Range("S" & Target.Row).Resize(, 4).Clear
      ElseIf LCase(Target.Value) = "cancel 1" Then
         With Range("S" & Target.Row).Resize(, 4)
            .Value = Evaluate("if(" & .Address & "<>""""," & .Address & "-1,"""")")
         End With
      End If
   End If
   Application.EnableEvents = True
End Sub
 

Forum statistics

Threads
1,089,597
Messages
5,409,194
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