VBA, Sumifs, Long

Akbarov

Active Member
Joined
Jun 30, 2018
Messages
347
Office Version
  1. 365
Platform
  1. Windows
Hello Dear Community,

Can anyone help me please? what am i doing wrong here?
IfCell and IsCell are sport names
SumCell is scores they achieved

VBA Code:
Sub test()
  Dim IfCell As Range, lr As Long
  Dim IsCell As Range
  Dim SumCell As Range, lr1 As Long
  Dim ResultCell As Range
  Dim CriteriaValue As String
  lr = Cells.Find("*", , xlValues, , xlRows, xlPrevious).Row
  lr1 = Cells.Find("*", , xlValues, , xlRows, xlPrevious).Row
  Set IfCell = Sheets("DATA").Range("ae25:ae2000")
  Set IsCell = Sheets("HISTOR").Range("F41")
  Set SumCell = Sheets("DATA").Range("AF25:AF2000")
  Set ResultCell = Sheets("HISTOR").Range("J41")

  CriteriaValue = "<>"

  ResultCell = WorksheetFunction.SumIfs(SumCell, IfCell, IsCell)
End Sub
 

Hello, Saurabhj

It is not complicated, Sumifs:
IfCell = Sheets("DATA").Range("ae25:ae2000") List Of Sports ( 16 different sports )
match
IsCell = Sheets("HISTOR").Range("F41") <--- Name of sport i am trying to sum results
Sum = Sheets("DATA").Range("AF25:AF2000") <--- This column is result of scores they achieved so they are numbers ( but formulas )

Instead of using range like AF25:AF2000 i want to use last.row but i forgot how to do that. ("AF25:AF") & lastrow

And finally i want result of calculation here:
ResultCell = Sheets("HISTOR").Range("J41")
lastRow = Worksheets("Data").Cells(Rows.Count, 31).End(xlUp).Row
 
Upvote 0

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
VBA Code:
Sub test()
  Dim IfCell As Range, lr As Long
  Dim IsCell As Range
  Dim SumCell As Range, lr1 As Long
  Dim ResultCell As Range, Cell As Range
  lr = Sheets("DATA").Cells(Rows.Count, 31).End(xlUp).Row
  lr1 = Sheets("DATA").Cells(Rows.Count, 32).End(xlUp).Row
  Set IfCell = Sheets("DATA").Range("AE25:AE" & lr)
Set SumCell = Sheets("DATA").Range("AF25:AF" & lr1)
  For Each Cell in Sheets("HISTOR").Range("F1:F45")
   Set IsCell = Cell
   Set ResultCell = Cell.offset(0, 4)
  'CriteriaValue = "<>"
  ResultCell = WorksheetFunction.SumIfs(SumCell, IfCell, IsCell)
Next Cell
End Sub
Sadly not works for me, how can i change F1:F45 to F40:F58 i don't understand this part Cell.offset(0, 4)
 
Upvote 0
Offset means number of rows & columns after your Criteria cell. if your Criteria cell is F40, then Offset( 0 , 4) don't change row ( 0) but add 4 column to your Criteria column. to Take Column J
Also You can change it to
VBA Code:
Set ResultCell = Sheets("HISTOR").Range("J" & Cell.Row)
you can change F1:F45 to F40:F58 no problem.

What is Error if not working. Are you add
VBA Code:
Dim Cell As Range
for Declaring Cell
 
Upvote 0
Solution
I checked now, in SUM range there are errors #Value how can i ignore error values?
 
Upvote 0
Thank you so much for help and information.
I never even dared to ask this question:
"I guess there is no any easy way to make this code to calculate from F1 to F45 and put results to J1 to J45"
 
Upvote 0
You're Welcome & thanks for feedback.
Don't Hesitate to Ask any question.
Or onebody answer or not. No Problem At All.
We have one Proverb:
Don't Knowing Not Fault, Don't Asking is Fault
 
Upvote 0

Forum statistics

Threads
1,214,952
Messages
6,122,458
Members
449,085
Latest member
ExcelError

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