KakarikoHero
New Member
- Joined
- Mar 3, 2023
- Messages
- 4
- Office Version
- 2013
- Platform
- Windows
I want to be able to have a value in the first cell to be "yes", "no", or "NA". Each column is a checklist for auditing. If "NA" is entered into column W the next X:AE cells to return "NA" because we can skip the row. I got that part easy peasy.
If cell W contains "No" I want cells Y:AA to be "NA" since those check points can't be audited. But i still want to edit the rest of the cells but cannot because of ".clearcontents"
Also, if Cell W contains "Yes" I want to clear all X:AE so that I can edit them as Yes or No.
Finally, if X is No then I want AB:AC to be "NA".
I was able to do this all with an IF function but wanted to step it up with VBA since once the cell is overwritten I lose the formula. So what can I use to still be able to edit these. Here's what I got. Please forgive how crude it is I was never trained in VBA.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim LastRow As Long
LastRow = Range("W" & Rows.Count).End(x1Up).Row
Dim i As Long
For i = 2 To LastRow
If Range("W" & i).Value = "NA" Then
Range("X" & i).Value = "NA"
Range("Y" & i).Value = "NA"
Range("Z" & i).Value = "NA"
Range("AA" & i).Value = "NA"
Range("AB" & i).Value = "NA"
Range("AC" & i).Value = "NA"
Range("AD" & i).Value = "NA"
Range("AE" & i).Value = "Account Closed"
ElseIf Range("W" & i).Value = "No" Then
Range("X" & i).ClearContents
Range("Y" & i).Value = "NA"
Range("Z" & i).Value = "NA"
Range("AA" & i).Value = "NA"
Range("AB" & i).ClearContents
Range("AC" & i).ClearContents
Range("AD" & i).ClearContents
Range("AE" & i).ClearContents
ElseIf Range("W" & i).Value = "Yes" Then
Range("X" & i).ClearContents
Range("Y" & i).ClearContents
Range("Z" & i).ClearContents
Range("AA" & i).ClearContents
Range("AB" & i).ClearContents
Range("AC" & i).ClearContents
Range("AD" & i).ClearContents
Range("AE" & i).ClearContents
End If
If Range ("X" & i).Value = "No" Then
Range("AB" & i).Value = "NA"
Range("AC" & i).Value = "NA"
ElseIf Range("X" & i).Value = "Yes" Then
Range("AB" & i).ClearContents
Range("AC" & i).ClearContents
End If
Next I
End Sub
Also, If anyone has suggestions for cleaning this up It would be greatly appreciated. Right now it's so clunky it causes Excel to lag
Thanks in advance!
If cell W contains "No" I want cells Y:AA to be "NA" since those check points can't be audited. But i still want to edit the rest of the cells but cannot because of ".clearcontents"
Also, if Cell W contains "Yes" I want to clear all X:AE so that I can edit them as Yes or No.
Finally, if X is No then I want AB:AC to be "NA".
I was able to do this all with an IF function but wanted to step it up with VBA since once the cell is overwritten I lose the formula. So what can I use to still be able to edit these. Here's what I got. Please forgive how crude it is I was never trained in VBA.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim LastRow As Long
LastRow = Range("W" & Rows.Count).End(x1Up).Row
Dim i As Long
For i = 2 To LastRow
If Range("W" & i).Value = "NA" Then
Range("X" & i).Value = "NA"
Range("Y" & i).Value = "NA"
Range("Z" & i).Value = "NA"
Range("AA" & i).Value = "NA"
Range("AB" & i).Value = "NA"
Range("AC" & i).Value = "NA"
Range("AD" & i).Value = "NA"
Range("AE" & i).Value = "Account Closed"
ElseIf Range("W" & i).Value = "No" Then
Range("X" & i).ClearContents
Range("Y" & i).Value = "NA"
Range("Z" & i).Value = "NA"
Range("AA" & i).Value = "NA"
Range("AB" & i).ClearContents
Range("AC" & i).ClearContents
Range("AD" & i).ClearContents
Range("AE" & i).ClearContents
ElseIf Range("W" & i).Value = "Yes" Then
Range("X" & i).ClearContents
Range("Y" & i).ClearContents
Range("Z" & i).ClearContents
Range("AA" & i).ClearContents
Range("AB" & i).ClearContents
Range("AC" & i).ClearContents
Range("AD" & i).ClearContents
Range("AE" & i).ClearContents
End If
If Range ("X" & i).Value = "No" Then
Range("AB" & i).Value = "NA"
Range("AC" & i).Value = "NA"
ElseIf Range("X" & i).Value = "Yes" Then
Range("AB" & i).ClearContents
Range("AC" & i).ClearContents
End If
Next I
End Sub
Also, If anyone has suggestions for cleaning this up It would be greatly appreciated. Right now it's so clunky it causes Excel to lag
Thanks in advance!