Consulting

Results 1 to 5 of 5

Thread: Summary

  1. #1
    VBAX Newbie
    Joined
    Jan 2012
    Posts
    5
    Location

    Summary

    Hello Experts,

    Another newbie here. I know this maybe very easy but I'd like to see the sample code for this summary for a table of data. For the sample data I attached, I'd like to automatically create a summary which the output should look like the one on the Summary Sheet. If I run the procedure, It will create the dates I specified for the summary as well as the data found in it.

    Sample data.xlsx

    *My example is a bit lame as I cant think of any data.

    Thank you so much for your guidance.

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Try this
    Attached Files Attached Files
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Newbie
    Joined
    Jan 2012
    Posts
    5
    Location
    Thank you so much md. I know this maybe too much but id like to create a vba code for this. Can you help? I've tried to create it but am having a hard time due to inexperience. Appreciate anything that could get me rolling with this. Thanks

  4. #4
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [vba]Sub Summary()
    Dim wsSrce As Worksheet, wsSumm As Worksheet

    Dim n As Range, Nms As Range, Dts As Range
    Dim r As Range

    Set wsSrce = Sheets("Source")
    Set wsSumm = Sheets("Summary")

    With wsSrce
    Set n = .Cells(Rows.Count, 1).End(xlUp)
    Set Nms = Range(n, n.End(xlUp))
    Set Dts = Range(.Cells(2, 2), .Cells(2, Columns.Count).End(xlToLeft))
    End With

    With wsSumm
    .Cells(1, 1) = "Late"
    .Cells(3, 1) = "Names"
    .Cells(2, 2) = "Date"
    Set r = .Cells(4, 1).Resize(Nms.Count)
    r.Value = Nms.Value
    For Each cel In Dts
    If IsDate(cel) Then
    i = i + 1
    .Cells(3, 1).Offset(, i) = cel.Value
    End If
    Next
    Set r = r.Offset(, 1).Resize(, i)

    r.FormulaR1C1 = _
    "=IF(OFFSET(Source!R1C1,MATCH(RC9,Source!C1,0)-1,MATCH(R3C,Source!R2,0)-1)=""Yes"",""Yes"","""")"

    CondFormat r
    Exit Sub
    End With
    End Sub

    Sub CondFormat(r As Range)

    r.FormatConditions.Add Type:=xlExpression, Formula1:="=B4=""Yes"""
    With r.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .ColorIndex = 3
    .TintAndShade = 0
    End With
    r.FormatConditions(1).StopIfTrue = True

    r.FormatConditions.Add Type:=xlExpression, Formula1:="=B4="""""
    With r.FormatConditions(2).Interior
    .PatternColorIndex = xlAutomatic
    .ColorIndex = 4
    .TintAndShade = 0
    End With
    r.FormatConditions(2).StopIfTrue = False
    End Sub[/vba]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    VBAX Newbie
    Joined
    Jan 2012
    Posts
    5
    Location
    Again thank you md. You're such a great help to this community.

Posting Permissions

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