How can I change this to a certain range rather than entire column?
Results 1 to 2 of 2

Thread: How can I change this to a certain range rather than entire column?
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    Mar 2019
    Posts
    48
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default How can I change this to a certain range rather than entire column?

    How can I refer to a range rather than entire column?

    Thanks


    Function Level5MakeMaterialCost()
    Dim R As Long
    Application.Volatile (True)
    R = Application.Caller.Row + 1
    Do While Cells(R, "BN").Value <> "Yes"
    If Cells(R, "BM") = "" Then Exit Do
    Level5MakeMaterialCost = Level5MakeMaterialCost + Val(Cells(R, "BM").Value)
    R = R + 1
    Loop
    End Function

  2. #2
    Board Regular
    Join Date
    Jul 2012
    Location
    Hampshire, UK
    Posts
    4,942
    Post Thanks / Like
    Mentioned
    21 Post(s)
    Tagged
    1 Thread(s)

    Default Re: How can I change this to a certain range rather than entire column?

    Hi,
    on idea maybe would be to add a range parameter to your function & pass the required range to it

    Code:
    Function Level5MakeMaterialCost(ByVal Target As Range)
        Dim cell As Range
        
        Application.Volatile
        
        For Each cell In Target.Cells
          If UCase(cell.Offset(, 1).Value) = "YES" Or cell.Value = "" Then Exit For
            Level5MakeMaterialCost = Level5MakeMaterialCost + Val(cell.Value)
        Next cell
    End Function

    Code:
    =Level5MakeMaterialCost(BM4:BM8)
    Dave

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •