Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

fixing sum specific values of date based on brand

0

hello

i have  this  code  it supposes giv me total of specific date based on brand  but  it gives me 0  

Sub Test9()
Dim rB As Range
Dim dResult As Double

Set rB = Range("a2", Range("a" & Rows.Count).End(xlUp))

dResult = Application.WorksheetFunction.SumIfs( _
    rB.Offset(0, 4), _
    rB, "<=" & DateSerial(2020, 1, 16), _
    rB.Offset(0, 1), "=1200R20")

MsgBox dResult
End Sub

i hope  some body help 

Answer
Discuss

Answers

0
Selected Answer

DateSerial(2020, 1, 16) converts to 16/1/2020 which isn't your intention, and neither does it work.

Your intention seems to have been CLng(DateSerial(2020, 1, 16)), and that does work.

Discuss

Discussion

hi, Variatus   it works thanks  for assistance   i  have one  thing it just curiosity if  is  available  i  try to  make  daynamic  i replace  this  line CLng(range("j2").value)   but  it  gives me  0   ,do you have any idea ?
leopard (rep: 88) Aug 9, '20 at 4:03 am
I checked this on your sample worksheet and find that 0 is the correct result. Try CLng(Range("A8")) instead of referring to J2.
Variatus (rep: 4889) Aug 9, '20 at 8:13 pm
thanks variatus  it works  perfectly  
Best regards,
leopard
leopard (rep: 88) Aug 10, '20 at 3:58 am
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login