#1   Report Post  
Posted to microsoft.public.excel.programming
al al is offline
external usenet poster
 
Posts: 363
Default Debug This

Quite simple Im sure

Dim x As Integer
x = 1
For x = 1 To 12
Worksheets(x).Select



Range("A5:I5").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Worksheets("Summary").Select
Range("a65536").Select
Selection.End(xlUp).Select
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
Next x

I am trying to copy the data from each sheet from a5:i5 down but it doesnt
work if there is nothing in the range. How do I fix it?
Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 272
Default Debug This

Try this. I shortened it up some for you.

Dim ws As Worksheet
x = 1
For x = 1 To 12
Set ws = Worksheets(x)
If ws.Range("A6") = "" Then
'Range is empty
MsgBox "Range is empty, Aborting Macro."
Exit Sub
End If
ws.Range(ws.Range("A5"), Range("I" & ws.Rows.Count).End(xlUp)).Copy _
Worksheets("Summary").Range("A" &
Worksheets("Summary").Rows.Count).End _
(xlUp).Offset(1)
Next x

--
Charles Chickering

"A good example is twice the value of good advice."


"Al" wrote:

Quite simple Im sure

Dim x As Integer
x = 1
For x = 1 To 12
Worksheets(x).Select



Range("A5:I5").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Worksheets("Summary").Select
Range("a65536").Select
Selection.End(xlUp).Select
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
Next x

I am trying to copy the data from each sheet from a5:i5 down but it doesnt
work if there is nothing in the range. How do I fix it?
Thanks!

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,311
Default Debug This

One way:

For x = 1 To 12
Worksheets(x).Select
Range("A5:I5").Select

Range(Selection, Selection.End(xlDown)).Select
If Selection.End(xlDown).Row < 65536 _
Then
Selection.Copy
Worksheets("Summary").Select
Range("A65536").End(xlUp).Select
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
Else:
End If
Next x


"Al" wrote in message
...
Quite simple Im sure

Dim x As Integer
x = 1
For x = 1 To 12
Worksheets(x).Select



Range("A5:I5").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Worksheets("Summary").Select
Range("a65536").Select
Selection.End(xlUp).Select
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
Next x

I am trying to copy the data from each sheet from a5:i5 down but it doesnt
work if there is nothing in the range. How do I fix it?
Thanks!



  #4   Report Post  
Posted to microsoft.public.excel.programming
al al is offline
external usenet poster
 
Posts: 363
Default Debug This

Thanks!

"PCLIVE" wrote:

One way:

For x = 1 To 12
Worksheets(x).Select
Range("A5:I5").Select

Range(Selection, Selection.End(xlDown)).Select
If Selection.End(xlDown).Row < 65536 _
Then
Selection.Copy
Worksheets("Summary").Select
Range("A65536").End(xlUp).Select
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
Else:
End If
Next x


"Al" wrote in message
...
Quite simple Im sure

Dim x As Integer
x = 1
For x = 1 To 12
Worksheets(x).Select



Range("A5:I5").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Worksheets("Summary").Select
Range("a65536").Select
Selection.End(xlUp).Select
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
Next x

I am trying to copy the data from each sheet from a5:i5 down but it doesnt
work if there is nothing in the range. How do I fix it?
Thanks!




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,311
Default Debug This

Just a thought Al.

In case the Selection to be copied only has one row the ending row would
still be 65536, thus causing you to lose that one row of data. So you may
want to adjust the code slightly. This will copy the single row range, even
when blank, and paste the blank selection to the next available row on the
destination sheet. The result is transparent and should not effect anything
when the row is blank. However, if it is a single row of data, then it gets
copied over as expected.

For x = 1 To 12
Worksheets(x).Select
Range("A5:I5").Select

If Selection.End(xlDown).Row < 65536 _
Then
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Worksheets("Summary").Select
Range("A65536").End(xlUp).Select
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
Else:
Selection.Copy
Worksheets("Summary").Select
Range("A65536").End(xlUp).Select
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
End If
Next x


HTH,
Paul

"Al" wrote in message
...
Thanks!

"PCLIVE" wrote:

One way:

For x = 1 To 12
Worksheets(x).Select
Range("A5:I5").Select

Range(Selection, Selection.End(xlDown)).Select
If Selection.End(xlDown).Row < 65536 _
Then
Selection.Copy
Worksheets("Summary").Select
Range("A65536").End(xlUp).Select
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
Else:
End If
Next x


"Al" wrote in message
...
Quite simple Im sure

Dim x As Integer
x = 1
For x = 1 To 12
Worksheets(x).Select



Range("A5:I5").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Worksheets("Summary").Select
Range("a65536").Select
Selection.End(xlUp).Select
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
Next x

I am trying to copy the data from each sheet from a5:i5 down but it
doesnt
work if there is nothing in the range. How do I fix it?
Thanks!








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
help with debug Rusty New Users to Excel 3 February 2nd 05 03:16 AM
debug John Excel Programming 0 September 22nd 04 04:11 AM
help with debug Jim May Excel Programming 2 August 10th 04 01:04 PM
No debug box mushy_peas[_33_] Excel Programming 2 April 23rd 04 12:20 AM
debug - [email protected] Excel Programming 1 March 6th 04 10:32 AM


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

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"