klnp_mysore
Board Regular
- Joined
- Mar 2, 2011
- Messages
- 64
Hi, Please any one can help me to find the sum of cells on condition and place it to a different cell
Public Sub Update()
Dim myrange As Range, _
myrange1 As Range
Set myrange = Range("U11:U1000")
Set myrange1 = Range("O10:O1000")
Range("M3").Value = (Application.SumIf(myrange1, "ywy(p)", myrange) / 1000) + _
(Application.SumIf(myrange1, "ywy(p)-fr", myrange) / 1000)
End Sub
Sub Update()
Dim myrange As Range
Dim myrange1 As Range
Dim sum As Range
Dim c As Range
Dim d As Range
Dim total As Double
Set myrange1 = Range("O10:O1000")
Set sum = Range("M3")
For Each c In myrange1
If c.Value = UCase("ywy(p)") Or c.Value = UCase("ywy(p)-fr") Then
total = total + c.Offset(0, 6).Value
End If
Next c
sum.Value = total / 1000
End Sub
Dim myrange As Range
Dim myrange1 As Range
Dim sum As Range
Dim c As Range
Dim d As Range
Dim total As Double
Set myrange1 = Range("O10:O1000")
Set sum = Range("M3")
For Each c In myrange1
If c.Value = UCase("ywy(p)") Or c.Value = UCase("ywy(p)-fr") Then
total = total + c.Offset(0, 6).Value
End If
Next c
sum.Value = total / 1000
Yes there is spaces
"ywy(p) - fr"
Is there any way to auto format, to remove the spaces even though user enters spaces.
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("O:O")) Is Nothing Then
Target.Value = Application.Substitute(Target.Value, " ", "")
End If
End Sub
Public Sub Update()
Dim myrange As Range, _
myrange1 As Range
Set myrange = Range("U11:U1000")
Set myrange1 = Range("O10:O1000")
Range("M3").Value = (Application.SumIf(myrange1, "ywy(p)", myrange) / 1000) + _
(Application.SumIf(myrange1, "ywy(p)-fr", myrange) / 1000)
End Sub