Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 173
Default If Range R Is Nothing Exit otherwise Copy Another Range

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 913
Default If Range R Is Nothing Exit otherwise Copy Another Range

On Wed, 24 Dec 2008 14:40:00 -0800, MikeF
wrote:

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default If Range R Is Nothing Exit otherwise Copy Another Range

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

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"MikeF" wrote in message
...
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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy Range to new Range and keep DATE format?? [email protected] Excel Programming 26 July 14th 08 12:19 PM
RANGE EXCEL copy cell that meets criteria in a range confused Excel Worksheet Functions 3 March 27th 08 01:41 PM
How do I edit a selected range then copy the range into an new sheet??? dwyborn Excel Programming 2 December 16th 05 04:11 PM
Macro to copy a specified range to a variable range SWT Excel Programming 4 October 21st 05 08:24 PM
Create/copy combo boxes in one range if condition is met in a different range LB[_4_] Excel Programming 4 September 30th 05 12:21 AM


All times are GMT +1. The time now is 02:41 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"