ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   SUM in VBA (https://www.excelbanter.com/excel-programming/365654-sum-vba.html)

Busybee

SUM in VBA
 
I am trying to sum col L on Data Sheet if Col A on Sales Reps matches Col K
on Data Sheet.. I have attempted it below but i failed. Any help?

Code:

  With Range("L2:L5000")
  sumL = 0
'assuming the row range is 2 to 5000
For r = 2 To 5000
  If Cells(Worksheets("Sales Reps")(r, 1)).Value = Cells(Worksheets("Data
Sheet")(r, 11)) Then
    sumL = sumL + Cells(Worksheets("Data Sheet")(r, 80)).Value
  End If
Next


Don Guillett

SUM in VBA
 
why not just adapt SUMIF to the vba. See the vba help for using functions in
code

--
Don Guillett
SalesAid Software

"Busybee" wrote in message
...
I am trying to sum col L on Data Sheet if Col A on Sales Reps matches Col K
on Data Sheet.. I have attempted it below but i failed. Any help?

Code:

  With Range("L2:L5000")
  sumL = 0
'assuming the row range is 2 to 5000
For r = 2 To 5000
  If Cells(Worksheets("Sales Reps")(r, 1)).Value = Cells(Worksheets("Data
Sheet")(r, 11)) Then
    sumL = sumL + Cells(Worksheets("Data Sheet")(r, 80)).Value
  End If
Next





Bob Phillips

SUM in VBA
 
With Range("H2:H5000")
.Formula = "=SUMPRODUCT(" & _
"--('Sales Reps'!A2:A5000='Data Sheet'!K2:K5000)," & _
"('Data Sheet'!CB2:CB5000))"
.Copy
.PasteSpecial Paste:=xlPasteValues
End With


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Busybee" wrote in message
...
I am trying to sum col L on Data Sheet if Col A on Sales Reps matches Col

K
on Data Sheet.. I have attempted it below but i failed. Any help?

Code:

  With Range("L2:L5000")
    sumL = 0
'assuming the row range is 2 to 5000
For r = 2 To 5000
  If Cells(Worksheets("Sales Reps")(r, 1)).Value = Cells(Worksheets("Data
Sheet")(r, 11)) Then
    sumL = sumL + Cells(Worksheets("Data Sheet")(r, 80)).Value
  End If
Next






All times are GMT +1. The time now is 10:17 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com