Consulting

Results 1 to 3 of 3

Thread: WorksheetFunction.Sum not working

  1. #1

    WorksheetFunction.Sum not working

    Hi All,

    I am trying to run the below code. All variables are getting value except 'rsum"

    
    Dim k As Integer, rsum As Double    
    Dim svalue As String    
    Dim numcol As Long   
     Dim strrng As Variant   
     Dim endrng As Variant        
       k = 7           
    
    
       Do While Sheets("BG").Cells(k, 11) <> ""     
    svalue = Sheets("BG").Cells(k, 11).Value      
    numcol = Application.WorksheetFunction.Match(svalue, Sheets(ws).range("$1:$1"), 0)        
    strrng = Sheets(ws).Cells(rstr, numcol).Address(False, False)       
    endrng = Sheets(ws).Cells(rend, numcol).Address(False, False)                       
    rsum = Application.WorksheetFunction.Sum(range(strrng, endrng))        
    Sheets("bg").Cells(k, 12).Value = rsum                
    k = k + 1        
    Debug.Print svalue        
    Debug.Print strrng        
    Debug.Print endrng        
    Debug.Print k       
     Debug.Print rsum                        
    Loop    
    End Sub



    Can anyone give me ideas why? I am using debug.print to get values. Except for rsum everything else seems okay!!

    rstr and rend are also working fine and m getting values for strrng and endrng

  2. #2
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Cross-posted Here

    Himanshuk, please read Here

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Marked solved.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Tags for this Thread

Posting Permissions

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