UDF For Each to end after certain range

VBE313

Board Regular
Joined
Mar 22, 2019
Messages
193
Office Version
365
Platform
Windows
I was thankful enough to receive a UDF from Rick Rothstein. https://www.mrexcel.com/forum/excel-questions/1101059-udf-sum-until-certain-column-not-blank-again-post5294214.html#post5294214

I was wondering if someone can help me and figure out a Do Until a certain range, I have to uses over 30 of these functions in one sheet and it calculates very very slow.

Function SumToYes()
Dim R As Long
R = Application.Caller.Row + 1
Do While Cells(R, "B").Value <> "Yes"
SumToYes = SumToYes + Val(Cells(R, "A").Value)
R = R + 1
Loop
End Function

Thanks
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
31,915
Office Version
365
Platform
Windows
Maybe
Code:
Function SumToYes()
  Dim R As Long
  R = Application.Caller.Row + 1
  Do While Cells(R, "B").Value <> "yes"
    If Cells(R, "A") = "" Then Exit Do
    SumToYes = SumToYes + Val(Cells(R, "A").Value)
    R = R + 1
  Loop
End Function
This will exit when col A is blank
 

VBE313

Board Regular
Joined
Mar 22, 2019
Messages
193
Office Version
365
Platform
Windows
Thank you Fluff! I am going to try this now.
 

Forum statistics

Threads
1,081,425
Messages
5,358,604
Members
400,505
Latest member
JacquiT

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top