Seniornetman
New Member
- Joined
- Dec 14, 2023
- Messages
- 6
- Office Version
- 365
- Platform
- Windows
I want to increment a number in one cell based on the letter P, T or A in another cell. How can I go about this?
No I mean the number 1 in A and it increments to 2 when P is entered in B
Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range, s
Set c = Intersect(Target, Range("B2"))
If c Is Nothing Then Exit Sub
s = UCase(c)
If s = "P" Or s = "T" Or s = "A" Then
Application.EnableEvents = False
Range("A2") = Range("A2") + 1
Application.EnableEvents = True
End If
End Sub
No I mean the number 1 in A and it increments to 2 when P is entered in B
OK I see what you have done here and I assume since my cells are G2 and L2 all I have to do change those B2 to L2 and A2 to g2 and it should work, correct? Also I assume since this will need to work in 38 cells I will re edit and put it in all 38?That will take VBA. With this if you enter P, T or A in B2. A2 will increment by 1
VBA Code:Private Sub Worksheet_Change(ByVal Target As Range) Dim c As Range, s Set c = Intersect(Target, Range("B2")) If c Is Nothing Then Exit Sub s = UCase(c) If s = "P" Or s = "T" Or s = "A" Then Application.EnableEvents = False Range("A2") = Range("A2") + 1 Application.EnableEvents = True End If End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range, d As Range, s
Set c = Intersect(Target, Range("L2:L38"))
If c Is Nothing Then Exit Sub
For Each d In c
s = UCase(d)
If s = "P" Or s = "T" Or s = "A" Then
Application.EnableEvents = False
d.Offset(, -6) = d.Offset(, -6) + 1
Application.EnableEvents = True
End If
Next
End Sub