Consulting

Results 1 to 3 of 3

Thread: Assign each trade a Trade ID

  1. #1
    VBAX Mentor
    Joined
    Aug 2011
    Posts
    353
    Location

    Assign each trade a Trade ID

    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..
    Attached Files Attached Files

  2. #2
    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.

  3. #3
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    @ Ashley

    Nice little sub.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •