Consulting

Results 1 to 7 of 7

Thread: Using name ranges with sumproduct?

  1. #1

    Using name ranges with sumproduct?

    = SUMPRODUCT(--(DAY(Sheet1!$F$2:$F$65536)=DAY(H$1)), --(Sheet1!$R$2:$R$65536=$C2), Sheet1!$AF$2:$AF$65536)
    + SUMPRODUCT(--(DAY(Sheet2!$F$2:$F$65536)=DAY(H$1)), --(Sheet2!$R$2:$R$65536=$C2), Sheet2!$AF$2:$AF$65536)

    The first part matches the day in H1 against column F in Sheet1
    The second part matches the name in C2 against column R in Sheet 1
    The last part adds the scores for the above 2 conditions.
    Then repeat for Sheet2

    The problems are: 1) The names I am checking against can also be in columns T and V, and 2) the scores to be returned can also be in columns AG and AH.

    Ultimately, I?d like to end up with something like this:
    If the date in Sheet1 and Sheet 2 column F matches the date in H1
    And the name in Sheet1 and Sheet2 columns R,T,V matches the name in C2
    Add the scores in Sheet1 and Sheet2 columns AF,AG,AH

    Can I use name ranges for dates and names to prevent some ugly formula? I have been unsuccessful in my attempts so far.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    =SUMPRODUCT((DAY(Sheet1!$F$2:$F$65)=DAY(H$1))*((Sheet1!$R$2:$R$65=$C2)+(She et1!$T$2:$T$65=$C2)+(Sheet1!$V$2:$V$65=$C2))*(Sheet1!$AF$2:$AH$65))
    +SUMPRODUCT((DAY(Sheet2!$F$2:$F$65)=DAY(H$1))*((Sheet2!$R$2:$R$65=$C2)+(She et2!$T$2:$T$65=$C2)+(Sheet2!$V$2:$V$65=$C2))*(Sheet2!$AF$2:$AH$65))
    ____________________________________________
    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
    Thanks Bob, but I get a #VALUE! Attached is a sample with your formula in it.

    My data set is really ugly and it needs to be rearranged in a simpler form to reduce the file size, hence what I am trying to do. As it stands, the data set is split between Sheet1 and Sheet2 as it contains 80K to 100K rows and about 40 columns. With a file size greater than 45Mb, it makes it very unstable and I also can’t do much with the file as when I try to calc anything it bombs out.

    So, the end result is to generate and save a Summary worksheet in another workbook so that I can do all my graphs, tables, and various calcs. Every week, I would then receive a new data set and update the links in the Summary table.

    Is there a better way to do this?

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    It is the blank cells Lawrence. If they were zeroes, it would work. But this will get enormously slow when you extend the range and copy for all datesand all employees.
    ____________________________________________
    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

  5. #5
    Thanks. I have to figure out how to extract the relevant information without excel locking up on me all the time.

  6. #6
    Alright, so I have done the following to reduce the size of the data file. I am sure there is a cleaner way to write this code, but it works.

    [vba]

    Option Explicit
    Dim DataTotalRows As Long

    Private Sub CommandButton1_Click()
    DataTotalRows = LastRow
    Range("A2:G65536").ClearContents
    ReduceData
    End Sub

    Private Function LastRow()
    Dim DataTotalRows As Long
    DataTotalRows = 1
    Do Until Worksheets("2008.04b").Cells(DataTotalRows, 1).Value = ""
    DataTotalRows = DataTotalRows + 1
    Loop
    LastRow = DataTotalRows - 1
    End Function

    Private Sub Worksheet_Activate()
    End Sub

    Private Sub ReduceData()
    Dim Date1 As String
    Dim Name1 As String
    Dim Name2 As String
    Dim Name3 As String
    Dim Pts1 As String
    Dim Pts2 As String
    Dim Pts3 As String
    Dim OutputA As String
    Dim OutputB As String
    Dim OutputC As String
    Dim OutputD As String
    Dim OutputE As String
    Dim OutputF As String
    Dim OutputG As String
    Dim LValue As String
    Dim RowIndex As Long
    Dim i As Long
    Dim k As Long
    Dim l As Long
    i = 0
    k = 2
    OutputA = "A2"
    OutputB = "B2"
    OutputC = "C2"
    OutputD = "D2"
    OutputE = "E2"
    OutputF = "F2"
    OutputG = "G2"
    RowIndex = 2
    Do Until i = DataTotalRows

    Date1 = Worksheets("2008.04b").Cells(RowIndex, 6).Value
    Name1 = Worksheets("2008.04b").Cells(RowIndex, 18).Value
    Name2 = Worksheets("2008.04b").Cells(RowIndex, 20).Value
    Name3 = Worksheets("2008.04b").Cells(RowIndex, 22).Value
    Pts1 = Worksheets("2008.04b").Cells(RowIndex, 32).Value
    Pts2 = Worksheets("2008.04b").Cells(RowIndex, 33).Value
    Pts3 = Worksheets("2008.04b").Cells(RowIndex, 34).Value

    Worksheets(Me.Name).Range(OutputA).Value = Date1
    Worksheets(Me.Name).Range(OutputB).Value = Name1
    Worksheets(Me.Name).Range(OutputC).Value = Name2
    Worksheets(Me.Name).Range(OutputD).Value = Name3
    Worksheets(Me.Name).Range(OutputE).Value = Pts1
    Worksheets(Me.Name).Range(OutputF).Value = Pts2
    Worksheets(Me.Name).Range(OutputG).Value = Pts3

    i = i + 1
    k = k + 1
    RowIndex = RowIndex + 1
    LValue = Str(k)
    OutputA = "A" & Trim(LValue)
    OutputB = "B" & Trim(LValue)
    OutputC = "C" & Trim(LValue)
    OutputD = "D" & Trim(LValue)
    OutputE = "E" & Trim(LValue)
    OutputF = "F" & Trim(LValue)
    OutputG = "G" & Trim(LValue)

    Loop

    End Sub
    [/vba]

    However, I'd like to also delete rows where columns B trough G are blank. I tried to do it, but it seems the cells are not really blank even though there is nothing in them.

    [vba]
    Sub DelBlanks()
    ActiveSheet.Range("B:G").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
    End Sub
    [/vba]
    Last edited by Lawrence; 08-21-2008 at 05:00 PM.

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I would add a formula to a spare column, a formula of

    =COUNTIF(B2:G2,"")=6

    and autofilter that column for TRUE, then delete all visible rows.
    ____________________________________________
    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

Posting Permissions

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