If Range R Is Nothing Exit otherwise Copy Another Range

M

MikeF

The subject pretty much says it all, code example as follows.
Should be ultimately simple.
But it doesn't work.
An "else without if" error appears.
Where am I going wrong??
Thanx,
- Mike


Sub APUcopy()

Dim r As Range
Set r = Range("a28")

If r Is Nothing Then Exit Sub
Else
Range("I7:I26").Copy Destination:=("i28.i47")
End If
End Sub
 
L

Lars-Åke Aspelin

The subject pretty much says it all, code example as follows.
Should be ultimately simple.
But it doesn't work.
An "else without if" error appears.
Where am I going wrong??
Thanx,
- Mike


Sub APUcopy()

Dim r As Range
Set r = Range("a28")

If r Is Nothing Then Exit Sub
Else
Range("I7:I26").Copy Destination:=("i28.i47")
End If
End Sub


Try with an new line after Then so that Exit Sub is on a separate
line.

Hope this helps / Lars-Åke
 
D

Don Guillett

To correct yours
Sub APUcopy()
Dim r As Range
Set r = Range("a28")
If Not r Is Nothing Then
Else
Range("I7:I26").Copy Destination:=Range("i28.i47")
End If
End Sub

I would have done it this way
Sub APUcopy1()
Dim r As Range
Set r = Range("a28")
If Len(Application.Trim(r)) > 0 Then' really blank
Range("I7:I26").Copy Range("i28")
End If
End Sub
 

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