0

Basically this code is reading column 2 which is JP's, and placing JT1,JT2 etc in another column but the catch is this, whenever a new JP is present in the next row, it'll restart the counter and always output JT1, but when there are multiple of the same JP it'll start a counter.

An example is like this:

JP1 --> JT1, JP2 --> JT1, JP2 --> JT2

Notice how when there is a unique JP it always is JT1, but once there is multiple of the same JP, the JT starts a counter like JT1, JT2, JT3 etc.

I am having trouble right now with this any help would be great.

Dim JobTask as String
Dim w1 as Workbook
Dim s1 as Worksheet
Dim row1 as Integer
Dim iteration as Integer

set w1 = ThisWorkbook
set s1 = w1.Sheets("Job Plan Sort")

For row1 = 9 To 16
JobPlan = s1.Cells(row1, 2).Value
JobTask = s1.Cells(row1, 3).Value


For iteration = row1 To 16
 If s1.Cells(iteration, 2) <> s1.Cells(iteration + 1, 2) Then

For j = row1 To (counter + row1)
                
                    s1.Cells(j, 3).Value = ("JT" + CStr(jtCounter))
                    
                Next j
                row1 = row1 + counter
                jtCounter = jtCounter + 1
                
                Exit For
                
         End If




            
     Next iteration
   



     Next row1

HERE IS SAMPLE OF OUTPUT AS REQUESTED

enter image description here

4
  • Feel like your request will create infinite loop? Commented Jun 11, 2021 at 16:25
  • Would really help to show sample input/expected output in your post. Commented Jun 11, 2021 at 17:57
  • Sure Ill add a sample Commented Jun 11, 2021 at 20:23
  • What about a sample input dataset? Commented Jun 12, 2021 at 0:41

1 Answer 1

1

Something like:

I2: ="JT"&COUNTIF($H$2:H2,H2)

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.