ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   If Else statement (https://www.excelbanter.com/excel-discussion-misc-queries/83421-if-else-statement.html)

Rokuro kubi

If Else statement
 
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


Dave Peterson

If Else statement
 
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.

Rokuro kubi wrote:

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


--

Dave Peterson

Rokuro kubi

If Else statement
 
Cheers Dave



All times are GMT +1. The time now is 10:08 AM.

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