WorksheetFunction.Sum not working

HimanshuK

New Member
Joined
Jun 14, 2016
Messages
23
Hi All,

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


Code:
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!!
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Hi All,

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


Rich (BB code):
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!!
Hi HimanshuK,

Try changing this line:

Rich (BB code):
rsum = Application.WorksheetFunction.Sum(range(strrng, endrng))

To this:

Rich (BB code):
rsum = Application.WorksheetFunction.Sum(Sheets(ws).range(strrng, endrng))
 
Upvote 0

Forum statistics

Threads
1,215,375
Messages
6,124,580
Members
449,174
Latest member
chandan4057

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