Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Error when No data to paste


Hi:

in Excel 2000 spk1, I have a sub that copies a range and pastes i
somewhere else. It works fine if there is data to be pasted but if th
range is empty is error out. Is there a way to bypass the error an
maybe have a msgbox come up and adivise the user?

this is a portion of my rookie code:

Range("BK5").Select
Range(ActiveCell, ActiveCell.End(xlDown)).Select
Selection.Cut
'
Range("A5").Select
Do
If ActiveCell.Select < "" Then
ActiveCell.Offset(1, 0).Select
End If
Loop Until ActiveCell = ""
'
ACTIVESHEET.PAST

When it goes to ActiveSheet.Paste, if it there's no data to paste i
errors out.


thank

--
halem
-----------------------------------------------------------------------
halem2's Profile: http://www.excelforum.com/member.php...nfo&userid=993
View this thread: http://www.excelforum.com/showthread.php?threadid=49469

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Error when No data to paste

Maybe something like:

Option Explicit
Sub testme()

Dim RngToCopy As Range
Dim CellToPaste As Range

With ActiveSheet
Set RngToCopy = .Range("Bk5", .Range("bk5").End(xlDown))
Set CellToPaste = .Range("a5")

Do
If CellToPaste.Value = "" Then
Exit Do
Else
Set CellToPaste = CellToPaste.Offset(1, 0)
End If
Loop
End With

If Application.CountA(RngToCopy) = 0 Then
'nothing in it
Else
RngToCopy.Cut _
Destination:=CellToPaste
End If

End Sub




halem2 wrote:

Hi:

in Excel 2000 spk1, I have a sub that copies a range and pastes it
somewhere else. It works fine if there is data to be pasted but if the
range is empty is error out. Is there a way to bypass the error and
maybe have a msgbox come up and adivise the user?

this is a portion of my rookie code:

Range("BK5").Select
Range(ActiveCell, ActiveCell.End(xlDown)).Select
Selection.Cut
'
Range("A5").Select
Do
If ActiveCell.Select < "" Then
ActiveCell.Offset(1, 0).Select
End If
Loop Until ActiveCell = ""
'
ACTIVESHEET.PASTE

When it goes to ActiveSheet.Paste, if it there's no data to paste it
errors out.

thanks

--
halem2
------------------------------------------------------------------------
halem2's Profile: http://www.excelforum.com/member.php...fo&userid=9930
View this thread: http://www.excelforum.com/showthread...hreadid=494694


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Error when No data to paste

Or maybe this if Bk5 is the only cell with something in it...

Option Explicit
Sub testme()

Dim RngToCopy As Range
Dim CellToPaste As Range
Dim NonBlankCells As Long

With ActiveSheet
Set RngToCopy = .Range("Bk5", .Range("bk5").End(xlDown))

Set CellToPaste = .Range("a5")

Do
If CellToPaste.Value = "" Then
Exit Do
Else
Set CellToPaste = CellToPaste.Offset(1, 0)
End If
Loop
End With

NonBlankCells = Application.CountA(RngToCopy)

If NonBlankCells = 0 Then
'nothing in it
Else
Set RngToCopy = RngToCopy.Resize(NonBlankCells, 1)
RngToCopy.Cut _
Destination:=CellToPaste
End If

End Sub

halem2 wrote:

Hi:

in Excel 2000 spk1, I have a sub that copies a range and pastes it
somewhere else. It works fine if there is data to be pasted but if the
range is empty is error out. Is there a way to bypass the error and
maybe have a msgbox come up and adivise the user?

this is a portion of my rookie code:

Range("BK5").Select
Range(ActiveCell, ActiveCell.End(xlDown)).Select
Selection.Cut
'
Range("A5").Select
Do
If ActiveCell.Select < "" Then
ActiveCell.Offset(1, 0).Select
End If
Loop Until ActiveCell = ""
'
ACTIVESHEET.PASTE

When it goes to ActiveSheet.Paste, if it there's no data to paste it
errors out.

thanks

--
halem2
------------------------------------------------------------------------
halem2's Profile: http://www.excelforum.com/member.php...fo&userid=9930
View this thread: http://www.excelforum.com/showthread...hreadid=494694


--

Dave Peterson
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 and paste subtotals-complex data range error Teri Excel Discussion (Misc queries) 1 March 6th 09 04:06 PM
Data Validation (copy paste error) Christoffer Bloch Andersen Excel Worksheet Functions 0 February 3rd 09 01:45 PM
Data Validation (copy paste error) Christoffer Bloch Andersen Excel Worksheet Functions 0 January 26th 09 11:53 AM
Special Paste Error...Data pastes into one column School Excel Discussion (Misc queries) 1 October 17th 07 06:48 PM
Cut and Paste using Macro gives paste special method error Lourens Pentz Excel Programming 3 November 21st 04 10:42 PM


All times are GMT +1. The time now is 01:29 PM.

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

About Us

"It's about Microsoft Excel"