How do I use VBA in Excel to check if a below cell is empty or not? I want to sum all values in a specific range, but only, if the below cell is not empty.
Is that s
I would recommend a Formula for this
FORMULA
=SUMPRODUCT((A1:E1)*(A2:E2<>""))
SNAPSHOT
If you still want VBA then
VBA
Option Explicit
Sub Sample()
Dim rng As Range
Dim Cl As Range
Dim tot As Long
Set rng = Range("A1:F1")
For Each Cl In rng
If Len(Trim(Cl.Offset(1))) <> 0 Then tot = tot + Cl.Value
Next
Debug.Print tot
End Sub
In fact you can have many versions in VBA. You can evaluate the above formula as well. For example
Option Explicit
Sub Sample()
Debug.Print Evaluate("=SUMPRODUCT((A1:E1)*(A2:E2<>""""))")
End Sub