ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   exit sub if no data (https://www.excelbanter.com/excel-programming/403606-exit-sub-if-no-data.html)

Daniel

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

Bob Phillips

exit sub if no data
 
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)



"Daniel" wrote in message
...
hi
How can I code so that my VBA will exit sub if no data in a row of a
column?
Thanks
Daniel




Daniel

exit sub if no data
 

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

"Bob Phillips" wrote:

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)



"Daniel" wrote in message
...
hi
How can I code so that my VBA will exit sub if no data in a row of a
column?
Thanks
Daniel





Dave Peterson

exit sub if no data
 
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.

Daniel wrote:

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

"Bob Phillips" wrote:

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)



"Daniel" wrote in message
...
hi
How can I code so that my VBA will exit sub if no data in a row of a
column?
Thanks
Daniel





--

Dave Peterson

Don Guillett

exit sub if no data
 
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

"Daniel" wrote in message
...

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

"Bob Phillips" wrote:

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)



"Daniel" wrote in message
...
hi
How can I code so that my VBA will exit sub if no data in a row of a
column?
Thanks
Daniel






Daniel

exit sub if no data
 
Thanks all
It works like a charm
Daniel

"Don Guillett" wrote:

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

"Daniel" wrote in message
...

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

"Bob Phillips" wrote:

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)



"Daniel" wrote in message
...
hi
How can I code so that my VBA will exit sub if no data in a row of a
column?
Thanks
Daniel







All times are GMT +1. The time now is 12:23 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com