How to increment a number in one cell based on a letter in another

Seniornetman

New Member
Joined
Dec 14, 2023
Messages
2
Office Version
  1. 365
Platform
  1. 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?
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Do you mean like this?

Book1
AB
1Letter
2PP1
3TT1
4PP2
5AA1
6TT2
7PP3
Sheet1
Cell Formulas
RangeFormula
B2:B7B2=IF(A2="","",A2&COUNTIF($A$2:A2,A2))
 
Upvote 0
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,215,079
Messages
6,122,998
Members
449,092
Latest member
masterms

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top