VBA: Function that sums an offset cell for every cell in a range

ackackack

New Member
Joined
Aug 21, 2015
Messages
9
Hello!

I am trying to develop a Function that will Sum the values in column F, but only if the cell's row has "Clinical" in column D. My spreadsheet looks like this:

h5ffqRV.png


While I was able to use the IF Function to perform this [ =SUM(VALUE(IF(D13="Clinical",F13,0)),VALUE(IF(D14="Clinical",F14,0)), ... ... and so on], but I ran into a character limit when I extended this formula down to row 300. Since this Formula should be able to apply indefinitely, I was hoping there was a cleaner macro solution to this.

This is what I developed so far, and I'm not quite sure how to make it work because I'm fairly new to VBA:

Code:
Function ClinicalSum()
Dim cl As Range
For Each cl In Range("D13:D300")
    If cl = “Clinical” Then
        cl.Value = ActiveCell(2,0)
    End If
Next cl

End Function

If anyone has any suggestions, that would be AWESOME. Let me know if anything needs to be clarified.

Thanks!!!!!!!
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Forum statistics

Threads
1,214,865
Messages
6,121,988
Members
449,060
Latest member
mtsheetz

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