+ Reply to Thread
Results 1 to 7 of 7

Counting DATA from one sheet and recognizing and input DATA to another "totals" sheet

Hybrid View

jrosko1 Counting DATA from one sheet... 12-20-2012, 11:32 AM
arlu1201 Re: Counting DATA from one... 01-04-2013, 06:43 AM
jrosko1 Re: Counting DATA from one... 01-04-2013, 08:53 AM
arlu1201 Re: Counting DATA from one... 01-04-2013, 09:49 AM
arlu1201 Re: Counting DATA from one... 01-04-2013, 09:24 AM
jrosko1 Re: Counting DATA from one... 01-04-2013, 09:26 AM
jrosko1 Re: Counting DATA from one... 01-04-2013, 10:57 AM
  1. #1
    Registered User
    Join Date
    06-21-2012
    Location
    GB, WI
    MS-Off Ver
    Excel 2010
    Posts
    41

    Counting DATA from one sheet and recognizing and input DATA to another "totals" sheet

    Various names will be input into column A for each month's sheet, along with company name in column B. For the Q1, etc, sheets, I need the names and corresponding companys from the individual month sheets to populate, along with the number of times the name appeared (# of occurrences). I manually input an example on the attached file. There will be a constantly changing group of over 200 names that could be entered in Column A, so having the name as part of the macro/formula won't work. Any help or suggestions on this is appreciated!
    THANK YOU!
    temp.xlsx

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,168

    Re: Counting DATA from one sheet and recognizing and input DATA to another "totals" sheet

    So do you want that the macro should populate the YEARLY tab with data from sheets Jan to Dec, while the Q1 sheets should take only data belong to Q1 which is Jan - Mar?
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Registered User
    Join Date
    06-21-2012
    Location
    GB, WI
    MS-Off Ver
    Excel 2010
    Posts
    41

    Re: Counting DATA from one sheet and recognizing and input DATA to another "totals" sheet

    Right, and a Q2 tab will only pull from April-June, Q3 august- october, and Q4 oct-dec.... (I thought I could add these later, but if it's helps now.....)

  4. #4
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,168

    Re: Counting DATA from one sheet and recognizing and input DATA to another "totals" sheet

    Try this code
    Option Explicit
    
    Sub update_sheets()
    Dim i As Long, lrow As Long, j As Long
    
    Application.ScreenUpdating = False
    
    For i = 1 To Worksheets.Count
        With Worksheets(i)
            If .Name = "Q1" Or .Name = "Q2" Or .Name = "Q3" Or .Name = "Q4" Or .Name = "YEARLY" Then
                lrow = .Range("A" & .Rows.Count).End(xlUp).Row
                If lrow > 1 Then .Range("A2:C" & lrow).ClearContents
            End If
        End With
    Next i
    
    For i = 1 To Worksheets.Count
        With Worksheets(i)
            If .Name <> "Q1" And .Name <> "Q2" And .Name <> "Q3" And .Name <> "Q4" And .Name <> "YEARLY" Then
                lrow = .Range("A" & .Rows.Count).End(xlUp).Row
                If lrow > 1 Then .Range("A2:B" & lrow).Copy Worksheets("YEARLY").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
            End If
            If .Name = "Jan" Or .Name = "Feb" Or .Name = "March" Then
                lrow = .Range("A" & .Rows.Count).End(xlUp).Row
                If lrow > 1 Then .Range("A2:B" & lrow).Copy Worksheets("Q1").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
            ElseIf .Name = "April" Or .Name = "May" Or .Name = "June" Then
                lrow = .Range("A" & .Rows.Count).End(xlUp).Row
                If lrow > 1 Then .Range("A2:B" & lrow).Copy Worksheets("Q2").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
            ElseIf .Name = "July" Or .Name = "Aug" Or .Name = "Sept" Then
                lrow = .Range("A" & .Rows.Count).End(xlUp).Row
                If lrow > 1 Then .Range("A2:B" & lrow).Copy Worksheets("Q3").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
            ElseIf .Name = "Oct" Or .Name = "Nov" Or .Name = "Dec" Then
                lrow = .Range("A" & .Rows.Count).End(xlUp).Row
                If lrow > 1 Then .Range("A2:B" & lrow).Copy Worksheets("Q4").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
            End If
        End With
    Next i
    
    For i = 1 To Worksheets.Count
        With Worksheets(i)
            If .Name = "Q1" Or .Name = "Q2" Or .Name = "Q3" Or .Name = "Q4" Or .Name = "YEARLY" Then
                .Sort.SortFields.Clear
                .Sort.SortFields.Add Key:=Range("A:A") _
                    , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
                .Sort.SortFields.Add Key:=Range("B:B") _
                    , SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
                With .Sort
                    .SetRange Range("A:C")
                    .Header = xlYes
                    .MatchCase = False
                    .Orientation = xlTopToBottom
                    .SortMethod = xlPinYin
                    .Apply
                End With
                lrow = .Range("A" & .Rows.Count).End(xlUp).Row
                If lrow > 1 Then
                    .Range("C2:C" & lrow).FormulaR1C1 = "=COUNTIF(C[-2],RC[-2])"
                    .Range("C2:C" & lrow).Value = .Range("C2:C" & lrow).Value
                End If
                For j = lrow To 2 Step -1
                    If .Range("A" & j).Value = .Range("A" & j - 1).Value Then .Rows(j).Delete
                Next j
            End If
        End With
    Next i
    
    MsgBox "Summary complete"
    
    Application.ScreenUpdating = True
    
    End Sub
    Copy the Excel VBA code
    Select the workbook in which you want to store the Excel VBA code
    Hold the Alt key, and press the F11 key, to open the Visual Basic Editor
    Choose Insert | Module
    Where the cursor is flashing, choose Edit | Paste

    To run the Excel VBA code:
    Choose View | Macros
    Select a macro in the list, and click the Run button

  5. #5
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,168

    Re: Counting DATA from one sheet and recognizing and input DATA to another "totals" sheet

    If you run the macro once and then make changes to the Jan - Dec sheets and you want to run the macro again, should the data in Q sheets and Yearly sheet be cleared and then fresh data input?

  6. #6
    Registered User
    Join Date
    06-21-2012
    Location
    GB, WI
    MS-Off Ver
    Excel 2010
    Posts
    41

    Re: Counting DATA from one sheet and recognizing and input DATA to another "totals" sheet

    yes, i think that would be great......

  7. #7
    Registered User
    Join Date
    06-21-2012
    Location
    GB, WI
    MS-Off Ver
    Excel 2010
    Posts
    41

    Re: Counting DATA from one sheet and recognizing and input DATA to another "totals" sheet

    truly awesome. Thank you tremendously for your help!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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