Consulting

Results 1 to 5 of 5

Thread: Seperate unique accounts and manipulate data

  1. #1

    Seperate unique accounts and manipulate data

    Hi

    Wonder if anyone has time to help create some code for following..

    Need to insert a line after every unique account in column K

    Need to change the sign on values in AB where value in O is Sell

    Need to sum values in AB for each unique account (in AB where the line was inserted)

    Have attached before (sheet1) and after (sheet2) if this helps - just a sample, actual sheet is a lot bigger of course

    Be really grateful for any help

    thanks
    Jon
    Attached Files Attached Files

  2. #2
    VBAX Expert
    Joined
    Sep 2016
    Posts
    788
    Location
    Option Explicit
    
    Sub test()
        Dim r As Range
        Dim v
        Dim i As Long
        
        Set r = Range("k1", Range("k1").End(xlDown)).Resize(, 18)
        
        v = r.Value
        
        For i = 1 To UBound(v)
            If v(i, 5) = "Sell" Then v(i, 18) = v(i, 18) * -1
        Next
        
        r.Value = v
        
        r.Rows(1).Insert xlDown
        Set r = Range("k1").Resize(i, 18)
        Application.DisplayAlerts = False
        r.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array(18), SummaryBelowData:=True
        Application.DisplayAlerts = True
        r.Rows(1).Delete xlUp
            
    End Sub

  3. #3
    Hi Mana,

    Code is good - any chance you could highlight the accounts that have total as 0.00 in green?

    But thanks very much
    regards
    Jon

  4. #4
    VBAX Expert
    Joined
    Sep 2016
    Posts
    788
    Location
    Option Explicit
    
    Sub test2()
        Dim r As Range
        Dim v
        Dim i As Long
        
        ActiveSheet.Copy
         
        Set r = Range("k1", Range("k1").End(xlDown)).Resize(, 18)
         
        v = r.Value
         
        For i = 1 To UBound(v)
            If v(i, 5) = "Sell" Then v(i, 18) = v(i, 18) * -1
        Next
         
        r.Value = v
          
        r.Columns(18).FormatConditions.Add( _
            Type:=xlExpression, _
            Formula1:="=AND(R[0]C[0]=0,ISBLANK(R[0]C[-13]))") _
            .Interior.Color = vbGreen
      
        r.Rows(1).Insert xlDown
        Set r = Range("k1").Resize(i, 18)
        Application.DisplayAlerts = False
        r.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array(18), SummaryBelowData:=True
        Application.DisplayAlerts = True
        r.Rows(1).Delete xlUp
         
    End Sub

  5. #5
    Thanks Mana

    regards
    Jon

Posting Permissions

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