PDA

View Full Version : insert sumifs with last row based on another sheet



SteveM99
10-25-2017, 12:21 PM
Having problems figuring out codes;


Here is regular excel formula:
=IF(glsum!D$29>0,+glsum!D5,+reportsum3!D5)

Here is my code

Dim Lastrow As Long
Lastrow = Worksheets("glsum").Columns("D").Find("*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows, LookIn:=xlValues).Row
Worksheets("reportsum4").Range("d5:d" & Lastrow).Formula = "=IF(glsum!D$" & LastRow & ")"&"">""&0,+glsum!D5,+reportsum3!D5)"


Was trying to insert the last row into the formula in vba (D29 is the last row on sheet GLsum, but it may change, and need to insert the formula in correctly. I am getting confused with the <>" and & parts.

SamT
10-25-2017, 01:49 PM
"=IF(glsum!D$" & LastRow & ")>0,+glsum!D5,+reportsum3!D5)"

"First part" & Variable & "Second part"

You might want to try a variant of
"=IF(glsum!D$" & LastRow & ")>0,'glsum'!D5,+reportsum3!D5)" :dunno:

SteveM99
10-25-2017, 02:40 PM
Thank for quick reply. I needed to add an "(" to your first formula and it worked. I also went back and did the same on mine it seemed to help make it work too. SOLVED!!!

SamT
10-25-2017, 02:51 PM
OOps!
"=IF(glsum!D$" & LastRow & ">0,+glsum!D5,+reportsum3!D5)"
OR
"=IF(glsum!D$" & LastRow & ">0,(+glsum!D5,+reportsum3!D5)"

SteveM99
10-25-2017, 03:34 PM
20755My file is getting a static save message but it won't close now. not sure what I did. I have a lot of macros in the file.

SamT
10-26-2017, 07:20 AM
My file is getting a static save message but it won't close now. not sure what I did. I have a lot of macros in the file.

SteveM99
10-26-2017, 10:24 AM
Not sure what you mean by directing me to read the FAQ. To look through the FAQ for the answer to my original questions, the pic (being a new question), or what should or should not be uploaded (the screen shot)?

SamT
10-26-2017, 04:55 PM
That's in my signature.

I'm so sorry, I just can't read your macros from my kitchen table