exit sub if no data

  • Thread starter Thread starter Daniel
  • Start date Start date
D

Daniel

hi
How can I code so that my VBA will exit sub if no data in a row of a column?
Thanks
Daniel
 
A row of a column? Do you mean a cell?

If Cells(the_row_num, "the_Column_letter").Value = "" Then Exit Sub

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
Thanks Bob
I code this at the begin of sub and cause error??

with activesheet
If Cells(2, "a").Value = "" Then
Exit Sub
end if
 
Could it be that you didn't include the "End with"

with activesheet
If .Cells(2, "a").Value = "" Then
Exit Sub
end if
end with

I added a dot in front of the cells() reference.

If this doesn't help, you should post the code and post the error message that
you see--and indicate which line causes the error.
 
You may have had the dreaded space bar in cell a2 so try
Sub exitif()
With ActiveSheet
'If Cells(2, "a").Value = "" Then Exit Sub
If Len(Application.Trim(Cells(2, "a"))) < 1 Then Exit Sub
MsgBox "hi"
End With
End Sub
 
Thanks all
It works like a charm
Daniel

Don Guillett said:
You may have had the dreaded space bar in cell a2 so try
Sub exitif()
With ActiveSheet
'If Cells(2, "a").Value = "" Then Exit Sub
If Len(Application.Trim(Cells(2, "a"))) < 1 Then Exit Sub
MsgBox "hi"
End With
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top