VBA for sumifs for visible cells only

NileshAPatel

New Member
Joined
May 29, 2021
Messages
26
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
HI
Please help to resolve error in below code

Wants to please sum formula in Cell E163 by selecting E6 to E162, but condition is to sum only those figure if corresponding cell in column D in not empty


Sub MM1()
Dim lr As Long, r As Long
lr = Cells(Rows.Count, "A").End(xlUp).Row

ActiveCell.Formula2R1C1 = _
"=SUMPRODUCT((R6C4:R&lrC4="""")* SUBTOTAL(109, OFFSET(R&[-lr]C, ROW(R&[-lr]C:R[-1]C)- ROW(R&[-lr]C),)))"

Range("E164").Select
End Sub

Thanks !!
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
How about
VBA Code:
ActiveCell.Formula2R1C1 = _
"=SUMPRODUCT((R6C4:R" & lr & "C4="""")* SUBTOTAL(109, OFFSET(R4C, ROW(R6C:R[-1]C)- ROW(R6C),)))"
 
Upvote 0
Thanks a lot , it get resolved, but needs one correction

currently it shows as
=SUMPRODUCT(($D$6:$D$162="")* SUBTOTAL(109, OFFSET(E$6, ROW(E$6:E162)- ROW(E$6),))) in place of E$6 it will show as E6 as shown below

=SUMPRODUCT(($D$6:$D$162="")* SUBTOTAL(109, OFFSET(E6, ROW(E6:E162)- ROW(E6),)))

Thanks
 
Upvote 0
Why do you need that as a relative reference?
 
Upvote 0

Forum statistics

Threads
1,214,991
Messages
6,122,628
Members
449,095
Latest member
bsb1122

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top