Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Pasting an Excel array
Can someone tell me why this code returns the #value! error
Dim J As Integer, val As Integer, arrnum As Variant arrnum = Evaluate("{=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + J & _ ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!K1:K1 1000)}") Thanks for any help This questions is related to my previous post Worksheets("main").Range("B18:B29").Value = arrnum |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Pasting an Excel array
Ram,
try: Dim J As Integer, val As Integer, arrnum As Variant arrnum = Evaluate("=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + J & _ ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!K1:K1 1000)") Worksheets("main").Range("B18:B29").FormulaArray = arrnum "ram" wrote: Can someone tell me why this code returns the #value! error Dim J As Integer, val As Integer, arrnum As Variant arrnum = Evaluate("{=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + J & _ ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!K1:K1 1000)}") Thanks for any help This questions is related to my previous post Worksheets("main").Range("B18:B29").Value = arrnum |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Pasting an Excel array
It returns all zero's
it should return values greater than a hundered based on my test data "Toppers" wrote: Ram, try: Dim J As Integer, val As Integer, arrnum As Variant arrnum = Evaluate("=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + J & _ ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!K1:K1 1000)") Worksheets("main").Range("B18:B29").FormulaArray = arrnum "ram" wrote: Can someone tell me why this code returns the #value! error Dim J As Integer, val As Integer, arrnum As Variant arrnum = Evaluate("{=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + J & _ ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!K1:K1 1000)}") Thanks for any help This questions is related to my previous post Worksheets("main").Range("B18:B29").Value = arrnum |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Pasting an Excel array
Hi again,
I tried this with data and computed a non-zero result arrnum = "=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + J & _ ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!K1:K1 1000)" Worksheets("main").Range("B18:B29").Formula = arrnum "ram" wrote: Can someone tell me why this code returns the #value! error Dim J As Integer, val As Integer, arrnum As Variant arrnum = Evaluate("{=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + J & _ ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!K1:K1 1000)}") Thanks for any help This questions is related to my previous post Worksheets("main").Range("B18:B29").Value = arrnum |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Pasting an Excel array
Sumproduct evaluates to a single number. arrnum is not an array, but a
single value. Not sure what the intent is to assign it to multiple cells. -- Regards, Tom Ogilvy "Toppers" wrote in message ... Hi again, I tried this with data and computed a non-zero result arrnum = "=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + J & _ ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!K1:K1 1000)" Worksheets("main").Range("B18:B29").Formula = arrnum "ram" wrote: Can someone tell me why this code returns the #value! error Dim J As Integer, val As Integer, arrnum As Variant arrnum = Evaluate("{=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + J & _ ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!K1:K1 1000)}") Thanks for any help This questions is related to my previous post Worksheets("main").Range("B18:B29").Value = arrnum |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Pasting an Excel array
arrnum will not be an array. sumproduct multiples arrays and sums the
results, returning a single value. -- Regards, Tom Ogilvy "ram" wrote in message ... It returns all zero's it should return values greater than a hundered based on my test data "Toppers" wrote: Ram, try: Dim J As Integer, val As Integer, arrnum As Variant arrnum = Evaluate("=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + J & _ ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!K1:K1 1000)") Worksheets("main").Range("B18:B29").FormulaArray = arrnum "ram" wrote: Can someone tell me why this code returns the #value! error Dim J As Integer, val As Integer, arrnum As Variant arrnum = Evaluate("{=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + J & _ ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!K1:K1 1000)}") Thanks for any help This questions is related to my previous post Worksheets("main").Range("B18:B29").Value = arrnum |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
Pasting an Excel array
This seems to be pasting the formula and I only want it to paste the values
"Toppers" wrote: Hi again, I tried this with data and computed a non-zero result arrnum = "=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + J & _ ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!K1:K1 1000)" Worksheets("main").Range("B18:B29").Formula = arrnum "ram" wrote: Can someone tell me why this code returns the #value! error Dim J As Integer, val As Integer, arrnum As Variant arrnum = Evaluate("{=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + J & _ ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!K1:K1 1000)}") Thanks for any help This questions is related to my previous post Worksheets("main").Range("B18:B29").Value = arrnum |
#8
Posted to microsoft.public.excel.programming
|
|||
|
|||
Pasting an Excel array
Hi,
Gone full circle: arrnum = Evaluate("=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + J & _ ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!K1:K1 1000)") Worksheets("main").Range("B18:B29").Value = arrnum the { } in the original formula were the problem! "ram" wrote: This seems to be pasting the formula and I only want it to paste the values "Toppers" wrote: Hi again, I tried this with data and computed a non-zero result arrnum = "=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + J & _ ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!K1:K1 1000)" Worksheets("main").Range("B18:B29").Formula = arrnum "ram" wrote: Can someone tell me why this code returns the #value! error Dim J As Integer, val As Integer, arrnum As Variant arrnum = Evaluate("{=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + J & _ ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!K1:K1 1000)}") Thanks for any help This questions is related to my previous post Worksheets("main").Range("B18:B29").Value = arrnum |
#9
Posted to microsoft.public.excel.programming
|
|||
|
|||
Pasting an Excel array
I appreciate all the help:
I have two sheets I was using the sumproduct function in each of the cells on my main sheet to return the totals based on the date and agent ID. However when I enter a new ID it takes a long time to update. So I wanted to replace all the sumproduct formulas with just the values. The code below accomplishes this for me. However it will place the value in each cell which is slowing the program down. I would like it to find the total for each cell and past them all at the same time. Thanks for any help 'moves date from main sheet to the agent history sheet Dim agtdetailnew As Range, csonew As Range, repnew As Range, othernew As Range, agtdetailhistory As Range, otherhistory As Range, csohistory As Range, rephistory As Range If ActiveSheet.Range("b3") = "" Then Range("b3").Select MsgBox "Please Enter Date" Range("b1").Select Else Set agtdetailnew = Worksheets("main").Range("b3:b8") Set othernew = Worksheets("main").Range("d4:d7") Set csonew = Worksheets("main").Range("f4:f13") Set repnew = Worksheets("main").Range("h4:h13") Set agtdetailhistory = Worksheets("agthistory").Cells(Rows.Count, "a").End(xlUp)(2) Set otherhistory = Worksheets("agthistory").Cells(Rows.Count, "a").End(xlUp)(2).Offset(0, 6) Set csohistory = Worksheets("agthistory").Cells(Rows.Count, "a").End(xlUp)(2).Offset(0, 10) Set rephistory = Worksheets("agthistory").Cells(Rows.Count, "a").End(xlUp)(2).Offset(0, 20) 'Range("a1:h1") = WorksheetFunction.Transpose(Range("a1:a8")) agtdetailnew.Copy agtdetailhistory.PasteSpecial 12, Transpose:=True othernew.Copy otherhistory.PasteSpecial 12, Transpose:=True csonew.Copy csohistory.PasteSpecial 12, Transpose:=True repnew.Copy rephistory.PasteSpecial 12, Transpose:=True Range("b1").Select End If 'Retrives the totals from agent history sheet and places the value on the main sheet Dim j As Integer For j = 1 To 12 Worksheets("main").Range("B" & 17 + j).Value = Evaluate("=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + j & ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!K1:K1 1000)") Worksheets("main").Range("C" & 17 + j).Value = Evaluate("=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + j & ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!L1:L1 1000)") Worksheets("main").Range("D" & 17 + j).Value = Evaluate("=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + j & ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!M1:M1 1000)") Worksheets("main").Range("E" & 17 + j).Value = Evaluate("=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + j & ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!N1:N1 1000)") Worksheets("main").Range("F" & 17 + j).Value = Evaluate("=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + j & ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!O1:O1 1000)") Worksheets("main").Range("G" & 17 + j).Value = Evaluate("=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + j & ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!P1:P1 1000)") Worksheets("main").Range("H" & 17 + j).Value = Evaluate("=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + j & ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!Q1:Q1 1000)") Worksheets("main").Range("I" & 17 + j).Value = Evaluate("=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + j & ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!R1:R1 1000)") Worksheets("main").Range("J" & 17 + j).Value = Evaluate("=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + j & ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!S1:S1 1000)") Worksheets("main").Range("K" & 17 + j).Value = Evaluate("=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + j & ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!T1:T1 1000)") Next j Thanks for any help "Tom Ogilvy" wrote: Sumproduct evaluates to a single number. arrnum is not an array, but a single value. Not sure what the intent is to assign it to multiple cells. -- Regards, Tom Ogilvy "Toppers" wrote in message ... Hi again, I tried this with data and computed a non-zero result arrnum = "=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + J & _ ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!K1:K1 1000)" Worksheets("main").Range("B18:B29").Formula = arrnum "ram" wrote: Can someone tell me why this code returns the #value! error Dim J As Integer, val As Integer, arrnum As Variant arrnum = Evaluate("{=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + J & _ ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!K1:K1 1000)}") Thanks for any help This questions is related to my previous post Worksheets("main").Range("B18:B29").Value = arrnum |
#10
Posted to microsoft.public.excel.programming
|
|||
|
|||
Pasting an Excel array
Do you know if this is possible?
Thanks "ram" wrote: I appreciate all the help: I have two sheets I was using the sumproduct function in each of the cells on my main sheet to return the totals based on the date and agent ID. However when I enter a new ID it takes a long time to update. So I wanted to replace all the sumproduct formulas with just the values. The code below accomplishes this for me. However it will place the value in each cell which is slowing the program down. I would like it to find the total for each cell and past them all at the same time. Thanks for any help 'moves date from main sheet to the agent history sheet Dim agtdetailnew As Range, csonew As Range, repnew As Range, othernew As Range, agtdetailhistory As Range, otherhistory As Range, csohistory As Range, rephistory As Range If ActiveSheet.Range("b3") = "" Then Range("b3").Select MsgBox "Please Enter Date" Range("b1").Select Else Set agtdetailnew = Worksheets("main").Range("b3:b8") Set othernew = Worksheets("main").Range("d4:d7") Set csonew = Worksheets("main").Range("f4:f13") Set repnew = Worksheets("main").Range("h4:h13") Set agtdetailhistory = Worksheets("agthistory").Cells(Rows.Count, "a").End(xlUp)(2) Set otherhistory = Worksheets("agthistory").Cells(Rows.Count, "a").End(xlUp)(2).Offset(0, 6) Set csohistory = Worksheets("agthistory").Cells(Rows.Count, "a").End(xlUp)(2).Offset(0, 10) Set rephistory = Worksheets("agthistory").Cells(Rows.Count, "a").End(xlUp)(2).Offset(0, 20) 'Range("a1:h1") = WorksheetFunction.Transpose(Range("a1:a8")) agtdetailnew.Copy agtdetailhistory.PasteSpecial 12, Transpose:=True othernew.Copy otherhistory.PasteSpecial 12, Transpose:=True csonew.Copy csohistory.PasteSpecial 12, Transpose:=True repnew.Copy rephistory.PasteSpecial 12, Transpose:=True Range("b1").Select End If 'Retrives the totals from agent history sheet and places the value on the main sheet Dim j As Integer For j = 1 To 12 Worksheets("main").Range("B" & 17 + j).Value = Evaluate("=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + j & ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!K1:K1 1000)") Worksheets("main").Range("C" & 17 + j).Value = Evaluate("=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + j & ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!L1:L1 1000)") Worksheets("main").Range("D" & 17 + j).Value = Evaluate("=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + j & ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!M1:M1 1000)") Worksheets("main").Range("E" & 17 + j).Value = Evaluate("=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + j & ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!N1:N1 1000)") Worksheets("main").Range("F" & 17 + j).Value = Evaluate("=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + j & ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!O1:O1 1000)") Worksheets("main").Range("G" & 17 + j).Value = Evaluate("=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + j & ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!P1:P1 1000)") Worksheets("main").Range("H" & 17 + j).Value = Evaluate("=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + j & ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!Q1:Q1 1000)") Worksheets("main").Range("I" & 17 + j).Value = Evaluate("=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + j & ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!R1:R1 1000)") Worksheets("main").Range("J" & 17 + j).Value = Evaluate("=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + j & ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!S1:S1 1000)") Worksheets("main").Range("K" & 17 + j).Value = Evaluate("=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + j & ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!T1:T1 1000)") Next j Thanks for any help "Tom Ogilvy" wrote: Sumproduct evaluates to a single number. arrnum is not an array, but a single value. Not sure what the intent is to assign it to multiple cells. -- Regards, Tom Ogilvy "Toppers" wrote in message ... Hi again, I tried this with data and computed a non-zero result arrnum = "=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + J & _ ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!K1:K1 1000)" Worksheets("main").Range("B18:B29").Formula = arrnum "ram" wrote: Can someone tell me why this code returns the #value! error Dim J As Integer, val As Integer, arrnum As Variant arrnum = Evaluate("{=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + J & _ ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!K1:K1 1000)}") Thanks for any help This questions is related to my previous post Worksheets("main").Range("B18:B29").Value = arrnum |
#11
Posted to microsoft.public.excel.programming
|
|||
|
|||
Pasting an Excel array
Hi Toppers,
i pasted in your code and now have have zero's returned. "Toppers" wrote: Hi, Gone full circle: arrnum = Evaluate("=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + J & _ ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!K1:K1 1000)") Worksheets("main").Range("B18:B29").Value = arrnum the { } in the original formula were the problem! "ram" wrote: This seems to be pasting the formula and I only want it to paste the values "Toppers" wrote: Hi again, I tried this with data and computed a non-zero result arrnum = "=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + J & _ ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!K1:K1 1000)" Worksheets("main").Range("B18:B29").Formula = arrnum "ram" wrote: Can someone tell me why this code returns the #value! error Dim J As Integer, val As Integer, arrnum As Variant arrnum = Evaluate("{=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + J & _ ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!K1:K1 1000)}") Thanks for any help This questions is related to my previous post Worksheets("main").Range("B18:B29").Value = arrnum |
#12
Posted to microsoft.public.excel.programming
|
|||
|
|||
Pasting an Excel array
As previously stated, Sumproduct does not return an array, so
arrnum = Evaluate("=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + J & _ ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!K1:K1 1000)") Worksheets("main").Range("B18:B29").Value = arrnum Will never work for a changing value of J. It will place the same number in B18:B29 if that is what is desired. For some sample tested code: Sub AAAB() For j = 1 To 12 arrNum = Evaluate("=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + j & _ ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!K1:K1 1000)") 'Range("B" & 17 + j).Value = arrNum Next Range("B18:B28").Value = arrNum End Sub put in the same number in every cell in B17:B26 Sub AAA() For j = 0 To 12 arrNum = Evaluate("=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + j & _ ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!K1:K1 1000)") Range("B" & 17 + j).Value = arrNum Next End Sub If the OP wants to generate all the answers in an array an place them all at once Sub AAA() Dim arrnum(1 to 12,1 to 1) as Long For j = 0 To 12 arrnum(j,1) = Evaluate("=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + j & _ ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!K1:K1 1000)") Next Range("B18:B29").Value = arrnum End sub -- Regards, Tom Ogilvy Put in the correct numbers (different in each cell). As I said, sumproduct returns a single number, not an array. "Toppers" wrote in message ... Hi, Gone full circle: arrnum = Evaluate("=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + J & _ ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!K1:K1 1000)") Worksheets("main").Range("B18:B29").Value = arrnum the { } in the original formula were the problem! "ram" wrote: This seems to be pasting the formula and I only want it to paste the values "Toppers" wrote: Hi again, I tried this with data and computed a non-zero result arrnum = "=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + J & _ ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!K1:K1 1000)" Worksheets("main").Range("B18:B29").Formula = arrnum "ram" wrote: Can someone tell me why this code returns the #value! error Dim J As Integer, val As Integer, arrnum As Variant arrnum = Evaluate("{=SUMPRODUCT((AGTHistory!A1:A11000=A" & 17 + J & _ ")*(AGTHistory!C1:C11000=Main!B5),AGTHistory!K1:K1 1000)}") Thanks for any help This questions is related to my previous post Worksheets("main").Range("B18:B29").Value = arrnum |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
VBA pasting array into cells | Excel Discussion (Misc queries) | |||
Pasting on Filtered Data Sheets without pasting onto hidden cells | Excel Discussion (Misc queries) | |||
pasting array output to sheet | Excel Programming | |||
Pasting an array into a range | Excel Programming | |||
Pasting a portion of an array | Excel Programming |