PDA

View Full Version : Assign each trade a Trade ID



Klartigue
12-09-2014, 09:51 AM
Using a VBA macro code, on the attached, I am trying to assign each trade a trade ID. Meaning that for each block of trades on the attached sheet, in column Q I would like to have a "1" for the all the lines in the first trade block, 2 for all the lines in the second trade block, etcc..

The number of trade blocks will vary and the size of each trade will always vary so its need to be a general formula but I am not sure how to go about doing this..


The file is attached and in column Q I have put the desired results..

ashleyuk1984
12-09-2014, 12:11 PM
Sub TradeIDNumbers()

TradeID = 0
StartHere = Cells.Find("Trade Allocation:").Row
FinishHere = Range("A" & Rows.Count).End(xlUp).Row


For x = StartHere To FinishHere
If Range("A" & x).Value > "" Then
If Range("A" & x).Value = "Trade Allocation:" Then
TradeID = TradeID + 1
Range("Q" & x).Value = TradeID
Else
Range("Q" & x).Value = TradeID
End If
End If
Next x


End Sub

Let me know how you get on.

SamT
12-09-2014, 03:57 PM
@ Ashley

Nice little sub.