If Else statement

  • Thread starter Thread starter Rokuro kubi
  • Start date Start date
R

Rokuro kubi

I'm fairly new to this and there are some frustrating gaps in what I
know of the basics. In the last section of code below, in the event
that DelRng6 = Nothing, how do I get the macro to simply move on to the
next code without doing anything else?

Dim DelRng6 As Range

Set myRng = Range(Cells(1, ActiveCell.Column), _
Cells(Rows.Count, ActiveCell.Column).End(xlUp))

For Each myCell In myRng.Cells
If myCell.Value = "Value" Then
If DelRng6 Is Nothing Then
Set DelRng6 = myCell
Else
Set DelRng6 = Union(myCell, DelRng6)
End If
End If
Next myCell

If DelRng6 Is Nothing Then
??????
Else
DelRng6.EntireRow.Delete

Range("B2").Delete
 
You could use:

If DelRng6 Is Nothing Then
Else
DelRng6.EntireRow.Delete
End if

or

If not (DelRng6 Is Nothing) Then
DelRng6.EntireRow.Delete
end if

I like:

If DelRng6 Is Nothing Then
'do nothing
Else
DelRng6.EntireRow.Delete
end if

I think it makes it easy to see what's happening.
 

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