+ Reply to Thread
Results 1 to 12 of 12

sumif issue

Hybrid View

  1. #1
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Response

    You might be better doing this one by macro which searches all the tabs and compiles the list on the summary tab depending upon what it finds. I guess that you will need to be careful that any one technician is given more than one ID on the separate tabs - even a slight difference in a way that the name was written would be enough to produce confusing results.

  2. #2
    Registered User
    Join Date
    03-17-2006
    MS-Off Ver
    2007
    Posts
    93
    OK... I've recorded a macro just for fun to do some mouse clicks, but have not done anything else, like actually writing code.

    Where to start that learning process?
    Better to be roughly right than exactly wrong, unless you are using Excel.

  3. #3
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Response

    You'll need something more that that you can record if you want to loop through all the sheets. If you want to find out more, have a look at the for...next loop in VBA help. (Alt F11 then help).

    Are you able to attach a copy of the workbook so that we can see the detail of what you are trying to achieve? - it should be then possible to give more useful advice.

  4. #4
    Registered User
    Join Date
    03-17-2006
    MS-Off Ver
    2007
    Posts
    93
    Yes sir.

    I have this small workbook as example.

    First two tabs are two cities with the end of day info that I will be using.


    Summary tab has headers with a description of what I need them to have in the columns.

    Of course, this will be expanded to 12 tabs, but I can handle that part.
    Attached Files Attached Files
    Last edited by redneck joe; 11-18-2006 at 05:03 PM.

  5. #5
    Forum Contributor
    Join Date
    07-05-2006
    Location
    Canada
    MS-Off Ver
    2003, 2007
    Posts
    581
    You can try this macro.

    Basically, it loops through all your sheets to gather data (excluding the one specified in the SUMMARY_NAME constant.

    It then puts the summary information in the SUMMARY_NAME sheet.

    It makes a couple of assumptions:

    First, that your employee ids are all numeric and below 50,000. You can adjust this upward, but it won't work with non-numeric employee ids.

    Second, that your description for being done is "complete".

    Third, the sheet you want to skip is "summary".

    Fourth, the columns listed in the example are the columns that you are actually using.

    Plus, some other little things in comments.

    Option Explicit
    
    Const MAX_EMPLOYEE_ID = 50000
    Const DESC_COMPLETE = "complete"
    Const SUMMARY_NAME = "summary"
    
    Public Sub Summarize()
      Dim WS As Worksheet
      Dim Start As Long
      Dim Finish As Long
      Dim Data(MAX_EMPLOYEE_ID, 1) As Long
      Dim i As Long
      Dim j As Long
      Dim current As Long
    
      'Gathering data... this goes through all sheets except the SUMMARY
      'sheet.
      For Each WS In Worksheets()
        If WS.Name <> SUMMARY_NAME Then
          Start = 2   'Assuming each sheet's data starts on Row 2
          Finish = WS.Range("A65536").End(xlUp).Row
              
          For i = Start To Finish
            With WS
              current = .Cells(i, 1)
              If (.Cells(i, 3) = DESC_COMPLETE) Then
                Data(current, 1) = Data(current, 1) + .Cells(i, 4)
              End If
              Data(current, 0) = Data(current, 0) + .Cells(i, 4)
            End With
          Next i
        End If
      Next
    
      'This puts the data in the SUMMARY sheet
      'For reference:
      '  i represents the row in our Data array.
      '  j represents the row in output, starting with row 2.
      j = 2
      For i = 0 To MAX_EMPLOYEE_ID
        If (Data(i, 0) <> 0 Or Data(i, 1) <> 0) Then
          With Worksheets(SUMMARY_NAME)
            .Cells(j, 1) = i
            .Cells(j, 2) = Data(i, 0)
            .Cells(j, 3) = Data(i, 1)
          End With
          j = j + 1
        End If
      Next i
    End Sub
    Scott

  6. #6
    Registered User
    Join Date
    03-17-2006
    MS-Off Ver
    2007
    Posts
    93
    your assumptions are all correct - could you possibly attach the workbook with the macro in it? I'm much better at tearing them down and figuring it out than I am at building from scratch...

  7. #7
    Forum Contributor
    Join Date
    07-05-2006
    Location
    Canada
    MS-Off Ver
    2003, 2007
    Posts
    581
    Ok, here you go.

    Just to ramble on, to use the code above, you're probably better to just copy it into your spreadsheet with all your data as opposed to copying all the data, although that is just a personal opinion. (I would also make a backup, in case things get screwed up. Full of confidence, aren't I?)

    All you have to do is go to VBA (Alt-F11), on the side, select the Workbook you want to put the macro in. Then choose Insert -> Module (Alt I - M), then paste the code in that module.

    Then you can run it with Alt-F8 and choose the procedure from the list.

    Scott
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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