Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
ali ali is offline
external usenet poster
 
Posts: 1
Default Mmm tricky- but i'm sure someone out there can help!


Hi everyone,

I've been trying to solve this for a while but its got me tearing my
hair out!!!

I want to create a macro that when run will summarise columns or rows
from different worksheets and return them to a new sheet that is
inserted at the front of the workbook.

In an ideal world the macro would bring up a box that would ask for the
rows or columns to be summarised. I would then enter the required
rows/columns ie, column a, click on ok and every column a in all the
worksheets would be returned to a new sheet at the front of the book.
ie if there are 3 sheets, column a of sheet 1 would be returned to
column a of new sheet, column a of sheet 2 would be returned to column
b of new sheet... etc to allow comparison.

I appreciate this is in all likelihood a large query but if anyone can
help in any way i'd be very grateful!


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/

~~Now Available: Financial Statements.xls, a step by step guide to creating financial statements
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Mmm tricky- but i'm sure someone out there can help!

Option Explicit
Sub Summarize()
Dim rng As Range, rng1 As Range
Dim sh As Worksheet, sh1 As Worksheet
Dim lngCol As Long, lngRow As Long
On Error Resume Next
Set rng = Application.InputBox("Select entirerow or entire column", Type:=8)
Set sh1 = Worksheets("Summary")
On Error GoTo 0
If rng.Rows.Count 1 Then
lngCol = rng.Column
Else
lngRow = rng.Row
End If
If Not sh1 Is Nothing Then
Application.DisplayAlerts = False
sh1.Delete
Application.DisplayAlerts = True
End If
Set sh = Worksheets.Add(Befo=Worksheets(1))
sh.Name = "Summary"
For Each sh1 In ActiveWorkbook.Worksheets
If sh1.Name < "Summary" Then
If lngCol 0 Then
sh1.Columns(lngCol).Copy Destination:= _
sh.Cells(1, "IV").End(xlToLeft)(1, 2)
Else
sh1.Rows(lngRow).Copy Destination:= _
sh.Cells(Rows.Count, 1).End(xlUp)(2)
End If
End If
Next
If lngCol 0 Then
sh.Cells(1, 1).EntireColumn.Delete
Else
sh.Cells(1, 1).EntireRow.Delete
End If
End Sub

if you have formulas on your sheets, you probably want to paste values
rather than do a straight paste:

Sub Summarize1()
Dim rng As Range, rng1 As Range
Dim sh As Worksheet, sh1 As Worksheet
Dim lngCol As Long, lngRow As Long
On Error Resume Next
Set rng = Application.InputBox("Select entirerow or entire column", Type:=8)
Set sh1 = Worksheets("Summary")
On Error GoTo 0
If rng.Rows.Count 1 Then
lngCol = rng.Column
Else
lngRow = rng.Row
End If
If Not sh1 Is Nothing Then
Application.DisplayAlerts = False
sh1.Delete
Application.DisplayAlerts = True
End If
Set sh = Worksheets.Add(Befo=Worksheets(1))
sh.Name = "Summary"
For Each sh1 In ActiveWorkbook.Worksheets
If sh1.Name < "Summary" Then
If lngCol 0 Then
sh1.Columns(lngCol).Copy
With sh.Cells(1, "IV").End(xlToLeft)(1, 2)
.PasteSpecial xlValues
.PasteSpecial xlFormats
End With
Else
sh1.Rows(lngRow).Copy
With sh.Cells(Rows.Count, 1).End(xlUp)(2)
.PasteSpecial xlValues
.PasteSpecial xlFormats
End With
End If
End If
Next
If lngCol 0 Then
sh.Cells(1, 1).EntireColumn.Delete
Else
sh.Cells(1, 1).EntireRow.Delete
End If
End Sub


--
Regards,
Tom Ogilvy



ali wrote in message
...

Hi everyone,

I've been trying to solve this for a while but its got me tearing my
hair out!!!

I want to create a macro that when run will summarise columns or rows
from different worksheets and return them to a new sheet that is
inserted at the front of the workbook.

In an ideal world the macro would bring up a box that would ask for the
rows or columns to be summarised. I would then enter the required
rows/columns ie, column a, click on ok and every column a in all the
worksheets would be returned to a new sheet at the front of the book.
ie if there are 3 sheets, column a of sheet 1 would be returned to
column a of new sheet, column a of sheet 2 would be returned to column
b of new sheet... etc to allow comparison.

I appreciate this is in all likelihood a large query but if anyone can
help in any way i'd be very grateful!


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/

~~Now Available: Financial Statements.xls, a step by step guide to

creating financial statements


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
This One Is Tricky Need Help !!!!! Mike Excel Discussion (Misc queries) 2 January 10th 10 04:50 PM
A Tricky One...... nevi Excel Worksheet Functions 3 June 18th 06 02:04 PM
This might be a little tricky...... nevi Excel Discussion (Misc queries) 2 June 17th 06 04:22 AM
Is it just me or is this tricky? philawde Excel Discussion (Misc queries) 7 November 23rd 05 03:58 PM
Tricky maybe Frazcmankfar Excel Worksheet Functions 0 August 18th 05 05:25 PM


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