Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using VBA to check if below cell is empty

Tags:

excel

vba

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 somehow possible with VBA or any other way?

Example:

4 2 3 2 1
2   3 1

Sum would be: 4 + 3 + 2 = 9.

like image 923
cherrun Avatar asked Apr 21 '12 22:04

cherrun


2 Answers

I've had some problems using just 'IsEmpty' when the data is exported from other databases. This is the function I've developed:

Function IsVacant(TheVar As Variant) As Boolean
  'LeandraG 2010

  IsVacant = False

  If IsEmpty(TheVar) Then IsVacant = True
  If Trim(TheVar) = "" Then IsVacant = True
  If Trim(TheVar) = "'" Then IsVacant = True


End Function
like image 180
LeasMaps Avatar answered Oct 11 '22 21:10

LeasMaps


Try this simple code

If IsEmpty(ActiveCell.Offset(1, 0)) Then
'your code here
End If
like image 22
Nick Avatar answered Oct 11 '22 23:10

Nick