Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Combine worksheet

I got a workbook which has 6 worksheets include 1 for total and 5 for staff to input the cheque no, amount and record no. Then I have to combine all the input to total, however, the no of item is not the same everytimes. So please help to use macro to copy and paste value of all input to one worksheet and automatically put under the next blank row, then count the no of cheque and sum the total of amount. Thanks!!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Combine worksheet

Sup?

Dim x As Integer
Dim y As Integer

For n = 2 To Sheets.Count 'If the "Totals" sheet is the last sheet the
this line should be "For n = 1 To Workbook.Sheets.Count - 1

With Worksheets(n)
x = .UsedRange.Row - 1 + .UsedRange.Rows.Count
y = .UsedRange.Column - 1 + .UsedRange.Columns.Count

.Range(.Cells(1, 1), .Cells(x, y)).Copy
End With

With Worksheets(1)
x = .UsedRange.Row + .UsedRange.Rows.Count
.Cells(x, 1).Insert
End With

Next n

- Piku

--
Message posted from http://www.ExcelForum.com

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Combine worksheet

hi
As my 5 worksheets within the workbook are not the same in size, e.g. (1) has 100 rows, (2) has 200 row. How to amend the macro to cater the different size and paste to the same worksheet "Total"

----- pikus wrote: ----

Sup

Dim x As Intege
Dim y As Intege

For n = 2 To Sheets.Count 'If the "Totals" sheet is the last sheet the
this line should be "For n = 1 To Workbook.Sheets.Count -

With Worksheets(n
x = .UsedRange.Row - 1 + .UsedRange.Rows.Coun
y = .UsedRange.Column - 1 + .UsedRange.Columns.Coun

.Range(.Cells(1, 1), .Cells(x, y)).Cop
End Wit

With Worksheets(1
x = .UsedRange.Row + .UsedRange.Rows.Coun
.Cells(x, 1).Inser
End Wit

Next

- Piku


--
Message posted from http://www.ExcelForum.com


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Combine worksheet

This works completely no matter the number or rows in any give sheet.
In fact it doesn't even care about the number of columns either. Thi
part:

With Worksheets(n)
x = .UsedRange.Row - 1 + .UsedRange.Rows.Count
y = .UsedRange.Column - 1 + .UsedRange.Columns.Count

.Range(.Cells(1, 1), .Cells(x, y)).Copy
End With

selects the entire used range of each page and copies it.
"UsedRange.Row" finds the FIRST row with information (presumably thi
would be the first row, but you can never be too careful.) The
"UsedRange.Rows.Count" returns the number of rows used and adds the
together. Now after you've added the first row (say 1) and the numbe
of used rows (say ten) the result (11) is actually the number of th
row immediately after the last used row so we must subtract 1 from th
sum.

After that's done,

With Worksheets(1)
x = .UsedRange.Row + .UsedRange.Rows.Count

finds the first empty row in the totals sheet (notice the 1 is no
subtracted) and pastes in the information.

If this is copying more cells than you want it to, I'd say you probabl
have information in cells you don't know about. Maybe some spaces or i
a font that's the same color as the background. If that does not solv
your roblem, just post more specifics. - Piku

--
Message posted from http://www.ExcelForum.com

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Combine worksheet

Hi
Thanks for your explanation. When I try to run the macro, excel has the following message:" The information cannot be pasted because the copy arean and the paste area are not the same size and shape. try one of the following: - click a single cell, then paste, - select a rectangle that's the same size and shape , and then paste." Please help

Regards
Janmy


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Combine worksheet

If you did not already do it this way, copy and paste the code to it'
destination. I tested it successfully and can only assume somethin
got lost in the translation somewhere. Let me know if that doesn'
work. - Piku

--
Message posted from http://www.ExcelForum.com

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
Combine data into central worksheet Candida Excel Worksheet Functions 1 May 18th 10 05:17 PM
How do I combine many worsheets into one worksheet?? Teric506 Excel Discussion (Misc queries) 6 November 21st 07 05:00 PM
How do I combine filtered data from one worksheet to another? DenverBuddafly Excel Discussion (Misc queries) 1 August 9th 07 08:02 PM
combine different worksheets to a single worksheet Norman Kong via OfficeKB.com Excel Discussion (Misc queries) 4 April 19th 05 12:46 PM
Macro to combine several worksheet formulas Emily Suskovich Excel Programming 3 January 20th 04 07:26 PM


All times are GMT +1. The time now is 04:00 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"