gurtejhira
New Member
- Joined
- Jul 28, 2015
- Messages
- 26
I have two rows A and B . I like to write a VBA with sumif statement . sum the data in B if the first letter in column A is 4 or 6 or 7.
Below mentioned is the code i tried but somehow its giving me only zero value. Please help me to identify what wrong i m doing.
Sub YardiDASR()
Dim a As Long, b As Long, c As Long
Dim lastrow As Long
Dim mycell As Range
a = 0
b = 0
c = 0
d = 0
lastrow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Row
For i = 3 To lastrow
If Left(Cells(i, 1), 1) = "4" Then
a = Cells(i, 7) + a
ElseIf Left(Cells(i, 1), 1) = "6" Then
b = Cells(i, 7) + b
ElseIf Left(Cells(i, 1), 1) = "7" Then
c = Cells(i, 7) + c
Else
d = Cells(i, 7) + d
End If
Next i
Range("J2") = a
Range("K2") = b
Range("L2") = c
Range("M2") = d
End Sub
Below mentioned is the code i tried but somehow its giving me only zero value. Please help me to identify what wrong i m doing.
Sub YardiDASR()
Dim a As Long, b As Long, c As Long
Dim lastrow As Long
Dim mycell As Range
a = 0
b = 0
c = 0
d = 0
lastrow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Row
For i = 3 To lastrow
If Left(Cells(i, 1), 1) = "4" Then
a = Cells(i, 7) + a
ElseIf Left(Cells(i, 1), 1) = "6" Then
b = Cells(i, 7) + b
ElseIf Left(Cells(i, 1), 1) = "7" Then
c = Cells(i, 7) + c
Else
d = Cells(i, 7) + d
End If
Next i
Range("J2") = a
Range("K2") = b
Range("L2") = c
Range("M2") = d
End Sub