Results 1 to 4 of 4

Need to display only unique employee name in summary - need some corrections in below code

Threaded View

aleanboy Need to display only unique... 10-09-2014, 07:41 AM
mehmetcik Re: Need to display only... 10-09-2014, 03:18 PM
aleanboy Re: Need to display only... 10-10-2014, 03:55 AM
aleanboy Re: Need to display only... 10-10-2014, 03:56 AM
  1. #1
    Forum Contributor
    Join Date
    09-15-2014
    Location
    london
    MS-Off Ver
    2013
    Posts
    111

    Need to display only unique employee name in summary - need some corrections in below code

    Hi team,

    Need small alteration with below code (Attached macro file for your reference).
    In details sheet I have employee “John” listed twice who is working under location “ARZN”. On clicking submit button in attached file, I need to have John displayed only once with qty as “187”.

    Please advise.
    Option Explicit
    
    Sub Extract_Stuff()
      Dim ws As Worksheet, ws1 As Worksheet
      Dim cel As Range
      Dim LR As Long, LR1 As Long, LC As Long, x As Long
    
      Set ws = Sheets("Details")
      Set ws1 = Sheets("Summary")
    
      Application.ScreenUpdating = False
      With ws1
        LR1 = .Cells.Find("*", .Cells(.Rows.Count, .Columns.Count), SearchOrder:=xlByRows, _
                          SearchDirection:=xlPrevious).Row
        If LR1 > 6 Then
          .Range("A7:F" & LR1).Cells.Clear
        End If
      End With
    
      If Not Evaluate("ISREF(Lists!A1)") Then
        Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Lists"
      Else
        Sheets("Lists").Cells.ClearContents
      End If
      With ws
    
        LR = .Cells.Find("*", .Cells(.Rows.Count, .Columns.Count), SearchOrder:=xlByRows, _
                         SearchDirection:=xlPrevious).Row
        LC = .Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByColumns, _
                         SearchDirection:=xlPrevious).Column
    
        .Columns("B:B").AdvancedFilter Action:=xlFilterCopy, _
                                       CopyToRange:=Sheets("Lists").Range("A1"), Unique:=True
        ActiveWorkbook.Names.Add Name:="Location", RefersTo:= _
                                 "=OFFSET(Lists!$A$2,0,0,(COUNTA(Lists!$A:$A)-1),1)"
        If Not .AutoFilterMode Then
          .Rows("1:1").AutoFilter
        End If
    
        For Each cel In Sheets("Lists").Range("Location")
          .Range(.Cells(1, 1), .Cells(LR, LC)).AutoFilter Field:=2, Criteria1:=cel.Value
          With .AutoFilter.Range
            x = .Columns(2).SpecialCells(xlCellTypeVisible).Count - 1
          End With
    
          .Range(.Cells(2, "C"), .Cells(LR, "D")).SpecialCells(xlCellTypeVisible).Copy
    
          With ws1
            LR1 = .Cells.Find("*", .Cells(.Rows.Count, .Columns.Count), SearchOrder:=xlByRows, _
                              SearchDirection:=xlPrevious).Row
            .Cells(LR1 + 1, "A").Value = cel.Value
            .Cells(LR1 + 1, "B").PasteSpecial
    
            .Cells(LR1 + 1, "A").Resize(x, 1).Merge
            .Cells(LR1 + 1, "A").VerticalAlignment = xlCenter
            .Cells(LR1 + 1, "A").HorizontalAlignment = xlCenter
            Application.CutCopyMode = False
          End With
        Next cel
        .AutoFilterMode = False
    
      End With
      Application.DisplayAlerts = False
      Sheets("Lists").Delete
      Application.DisplayAlerts = True
      ws1.Activate
      Application.ScreenUpdating = True
    End Sub
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 2
    Last Post: 10-09-2014, 05:18 AM
  2. [SOLVED] Formula to calculate unique values for an employee
    By irishguurl in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 05-16-2013, 03:15 PM
  3. [SOLVED] Need to aggregate employee timesheets into a summary sheet
    By cfell in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-23-2013, 02:03 PM
  4. Grab unique values affiliated with a unique employee
    By texaschili in forum Excel General
    Replies: 2
    Last Post: 07-13-2010, 10:52 AM
  5. automated employee tenure summary using Customized Charts with VBA
    By tweety127 in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 05-22-2006, 02:24 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1