Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions,microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default Select used range

Hi,

I have workbook with 5 to 6 sheets.

I need to copy all the details to sheet named "TOTAL"

Below code will go through all the sheets & from Cell A2 to used range
it will copy and paste in sheet "TOTAL"

Below code some problem i guess,
I have used If condition, can anyone give more simple coding better
than if conditon.

and Is there any other coding (ActiveSheet.UsedRange.Rows.Count ) to
count the number rows used and column apart from what ever i have
mentioned ?

Range("A2", Range("A2").Offset(lastrow, lastcol)).Select - Better line
code than this ? can anyone suggest me.

Sub group()
Dim i As Integer

Application.ScreenUpdating = False
For i = 2 To Sheets.Count

Worksheets(i).Select
lastrow = ActiveSheet.UsedRange.Rows.Count
lastcol = ActiveSheet.UsedRange.Columns.Count

Range("A2", Range("A2").Offset(lastrow, lastcol)).Select
Selection.Copy
Range("A1").Select
Worksheets("total").Select
Range("A2").Select

If Range("A2").Value = "" Then
ActiveSheet.Paste
Else
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
End If


Next
Application.ScreenUpdating = True
Application.CutCopyMode = False

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,501
Default Select used range

Hi,

From your mmessage header I guess your trying to copy the used range of each
sheet so try this

Sub group()
Dim i As Long
For i = 2 To Sheets.Count
lastrow = Worksheets("total").Cells(Rows.Count, "A").End(xlUp).Row
Worksheets(i).UsedRange.Copy _
Destination:=Worksheets("total").Cells(lastrow + 1, 1)
Next
End Sub

Mike


" wrote:

Hi,

I have workbook with 5 to 6 sheets.

I need to copy all the details to sheet named "TOTAL"

Below code will go through all the sheets & from Cell A2 to used range
it will copy and paste in sheet "TOTAL"

Below code some problem i guess,
I have used If condition, can anyone give more simple coding better
than if conditon.

and Is there any other coding (ActiveSheet.UsedRange.Rows.Count ) to
count the number rows used and column apart from what ever i have
mentioned ?

Range("A2", Range("A2").Offset(lastrow, lastcol)).Select - Better line
code than this ? can anyone suggest me.

Sub group()
Dim i As Integer

Application.ScreenUpdating = False
For i = 2 To Sheets.Count

Worksheets(i).Select
lastrow = ActiveSheet.UsedRange.Rows.Count
lastcol = ActiveSheet.UsedRange.Columns.Count

Range("A2", Range("A2").Offset(lastrow, lastcol)).Select
Selection.Copy
Range("A1").Select
Worksheets("total").Select
Range("A2").Select

If Range("A2").Value = "" Then
ActiveSheet.Paste
Else
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
End If


Next
Application.ScreenUpdating = True
Application.CutCopyMode = False

End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 51
Default Select used range

That's good one, thanks mike

but one thing in your it will copy used range but i want to ignore the
header row of all the sheets.
so how can i modify the code.



On Feb 19, 1:00*am, Mike H wrote:
Hi,

From your mmessage header I guess your trying to copy the used range of each
sheet so try this

Sub group()
Dim i As Long
For i = 2 To Sheets.Count
lastrow = Worksheets("total").Cells(Rows.Count, "A").End(xlUp).Row
Worksheets(i).UsedRange.Copy _
Destination:=Worksheets("total").Cells(lastrow + 1, 1)
Next
End Sub

Mike

" wrote:
Hi,


I have workbook with 5 to 6 sheets.


I need to copy all the details to sheet named "TOTAL"


Below code will go through all the sheets & from Cell A2 to used range
it will copy and paste in sheet "TOTAL"


Below code some problem i guess,
I have used If condition, can anyone give more simple coding better
than if conditon.


and Is there any other coding (ActiveSheet.UsedRange.Rows.Count ) to
count the number rows used and column apart from what ever i have
mentioned ?


Range("A2", Range("A2").Offset(lastrow, lastcol)).Select - Better line
code than this ? can anyone suggest me.


Sub group()
Dim i As Integer


Application.ScreenUpdating = False
For i = 2 To Sheets.Count


Worksheets(i).Select
lastrow = ActiveSheet.UsedRange.Rows.Count
lastcol = ActiveSheet.UsedRange.Columns.Count


Range("A2", Range("A2").Offset(lastrow, lastcol)).Select
Selection.Copy
Range("A1").Select
Worksheets("total").Select
Range("A2").Select


If Range("A2").Value = "" Then
* *ActiveSheet.Paste
* * Else
* *Selection.End(xlDown).Select
* ActiveCell.Offset(1, 0).Select
* * ActiveSheet.Paste
End If


Next
Application.ScreenUpdating = True
Application.CutCopyMode = False


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
How can change range to select active rows instead of :=Range("S10 ldiaz Excel Discussion (Misc queries) 7 August 29th 08 03:52 PM
macro to select range from active cell range name string aelbob Excel Programming 2 July 14th 08 09:19 PM
When entering data into a range of cells, select the entire range. Q Excel Discussion (Misc queries) 0 September 26th 07 04:36 AM
Compare a selected Range with a Named range and select cells that do not exist PCLIVE Excel Programming 1 October 18th 05 07:09 PM
Select Sheet then Select Range Gee[_2_] Excel Programming 3 May 27th 04 10:10 PM


All times are GMT +1. The time now is 08:20 PM.

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"