If statement and exit macro

G

Guest

I want that is the statement is true, give me a message and stop the macro,
if cell Ki is empty. If the cell contain data I would like to continue with
the macro. But when I run the macro for test, if the cell contain data gave
me the message and top the macro. What is wrong?

For i = 1 To nLastRow + 1 - nFirstRow
If Trim(wsSystem.Cells(i, 11)) = "" Or IsEmpty(wsSystem.Cells(i,
11)) Or IsNull(wsSystem.Cells(i, 11)) Then
MsgBox "You do not indicated if the System need a Critical or
Non-Critical Overall Assessment"
Exit Sub
End If
Next i
 
G

Guest

abdrums,

I tried this code out on a test sheet, and it worked fine for me. Are you
sure you are defining your row variables correctly? Try using the Immediate
Window and Debug.Print to follow the code, also.

Pflugs
 
D

Dave Peterson

What was in the cell that gave you the warning?
(Maybe adding
msgbox wssystem.cells(i,11).value & vblf & i
would help)

And I'd just use that first portion to check for "emptyness":

If Trim(wsSystem.Cells(i, 11).value) = "" then


If the cell is empty, then trim() will be "". And isnull doesn't do what you
think.
 

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

Top