Consulting

Results 1 to 3 of 3

Thread: Solved: Creating Formulas for Dynamic Ranges using VBA

  1. #1

    Solved: Creating Formulas for Dynamic Ranges using VBA

    Hello Everyone,

    I am looking to create some formulas in the columnar format that an Excel pivot table failed to do. My problem is that this data is going to change daily so I can't add formulas and copy down because :

    1) the data sets are 32K rows and 5 tabs
    2) Time

    So I would appreciate any help on this one. I would need to calculate the % of Cable Total and then all sum the total calls. I have attached the spreadsheet with the before and after.

    Many thanks for your thoughts and suggestions

    Slice

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Public Sub ProcessData()
    Dim i As Long
    Dim LastRow As Long
    Dim cell As Range
    Dim FirstAddress As String
    With ActiveSheet

    LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
    .Range("D2").Resize(LastRow - 1).Formula = "=IF(ISNUMBER(SEARCH(""Total"",A2)),"""",C2/SUMIF(A:A,A2,C:C))"
    Set cell = .Columns(1).Find("Total", LookIn:=xlValues, LookAT:=xlPart)
    i = 2
    If Not cell Is Nothing Then
    FirstAddress = cell.Address
    Do
    If cell.Row < LastRow Then
    cell.Offset(0, 6).Formula = "=SUM(G" & i & ":G" & cell.Row - 1 & ")"
    End If
    i = cell.Row + 1
    Set cell = .Columns(1).FindNext(cell)
    Loop While Not cell Is Nothing And cell.Address <> FirstAddress
    End If
    End With

    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Xld,

    Once again you have saved the day! Many thanks for this.

Posting Permissions

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