Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 56
Default Help with Mr. Dave Peterson's Code for Consolidating Many Sheets to One

Hello All,
Following is the macro posted by Mr. Dave Peterson. It works fine

Option Explicit
Option Base 0
Sub testme2()
Dim newWks As Worksheet
Dim wks As Worksheet
Dim DestCell As Range
Dim RngToCopy As Range
Dim iCtr As Long
Dim myAddresses As Variant
Dim oRow As Long
'billed, balance, due
myAddresses = Array("a55", "a56", "a57")

Set newWks = Worksheets.Add(after:=Worksheets(Worksheets.Count) )

With newWks
.Name = "Cons " & Format(Now, "yyyymmdd_hhmmss")
.Range("a1").Resize(1, 4).Value _
= Array("PartyName", "TotalBilled", "TotalBalance",
"TotalDue")
oRow = 1
End With

For Each wks In ActiveWorkbook.Worksheets
If wks.Name = newWks.Name Then
'do nothing
Else
oRow = oRow + 1
With wks
newWks.Cells(oRow, "A").Value = .Name
For iCtr = LBound(myAddresses) To UBound(myAddresses)
newWks.Cells(oRow, "A").Offset(0, 1 + iCtr).Value
_
= .Range(myAddresses(iCtr)).Value
Next iCtr
End With
End If
Next wks

End Sub
<<<
The macro makes a Consolidated Worksheet (Cons) of all the worksheets. I
need to have the following changes to take place in the consolidated
worksheet
1) Set the ColumnWidth to Autofit
2) Have the Sum (Total) at the bottom for each Column (starting from B
onwards).

Any suggestions please
TIA
Rashid


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Help with Mr. Dave Peterson's Code for Consolidating Many Sheets to One

Option Explicit
Option Base 0
Sub testme2()
Dim newWks As Worksheet
Dim wks As Worksheet
Dim DestCell As Range
Dim RngToCopy As Range
Dim iCtr As Long
Dim myAddresses As Variant
Dim rng as Range
Dim oRow As Long
'billed, balance, due
myAddresses = Array("a55", "a56", "a57")

Set newWks = Worksheets.Add(after:=Worksheets(Worksheets.Count) )

With newWks
.Name = "Cons " & Format(Now, "yyyymmdd_hhmmss")
.Range("a1").Resize(1, 4).Value _
= Array("PartyName", "TotalBilled", _
"TotalBalance", "TotalDue")
oRow = 1
End With

For Each wks In ActiveWorkbook.Worksheets
If wks.Name = newWks.Name Then
'do nothing
Else
oRow = oRow + 1
With wks
newWks.Cells(oRow, "A").Value = .Name
For iCtr = LBound(myAddresses) To UBound(myAddresses)
newWks.Cells(oRow, "A").Offset(0, 1 + iCtr).Value _
= .Range(myAddresses(iCtr)).Value
Next iCtr
End With
End If
Next wks
for iCtr = 2 to Ubound(MyAddresses) + 2
set rng = newWks.Cells(rows.count,iCtr).end(xlup)(2)
rng.FormulaR1C1 = "=Sum(R2C:R[-1]C)"
Next
newWks.Columns.Autofit
End Sub

--
Regards,
Tom Ogilvy

"Rashid Khan" wrote in message
...
Hello All,
Following is the macro posted by Mr. Dave Peterson. It works fine

Option Explicit
Option Base 0
Sub testme2()
Dim newWks As Worksheet
Dim wks As Worksheet
Dim DestCell As Range
Dim RngToCopy As Range
Dim iCtr As Long
Dim myAddresses As Variant
Dim oRow As Long
'billed, balance, due
myAddresses = Array("a55", "a56", "a57")

Set newWks = Worksheets.Add(after:=Worksheets(Worksheets.Count) )

With newWks
.Name = "Cons " & Format(Now, "yyyymmdd_hhmmss")
.Range("a1").Resize(1, 4).Value _
= Array("PartyName", "TotalBilled", "TotalBalance",
"TotalDue")
oRow = 1
End With

For Each wks In ActiveWorkbook.Worksheets
If wks.Name = newWks.Name Then
'do nothing
Else
oRow = oRow + 1
With wks
newWks.Cells(oRow, "A").Value = .Name
For iCtr = LBound(myAddresses) To UBound(myAddresses)
newWks.Cells(oRow, "A").Offset(0, 1 + iCtr).Value
_
= .Range(myAddresses(iCtr)).Value
Next iCtr
End With
End If
Next wks

End Sub
<<<
The macro makes a Consolidated Worksheet (Cons) of all the worksheets. I
need to have the following changes to take place in the consolidated
worksheet
1) Set the ColumnWidth to Autofit
2) Have the Sum (Total) at the bottom for each Column (starting from B
onwards).

Any suggestions please
TIA
Rashid




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 56
Default Help with Mr. Dave Peterson's Code for Consolidating Many Sheets to One

Hello Tom,
It works like a charm. U r a great help... as always.
Rashid

"Tom Ogilvy" wrote in message
...
Option Explicit
Option Base 0
Sub testme2()
Dim newWks As Worksheet
Dim wks As Worksheet
Dim DestCell As Range
Dim RngToCopy As Range
Dim iCtr As Long
Dim myAddresses As Variant
Dim rng as Range
Dim oRow As Long
'billed, balance, due
myAddresses = Array("a55", "a56", "a57")

Set newWks = Worksheets.Add(after:=Worksheets(Worksheets.Count) )

With newWks
.Name = "Cons " & Format(Now, "yyyymmdd_hhmmss")
.Range("a1").Resize(1, 4).Value _
= Array("PartyName", "TotalBilled", _
"TotalBalance", "TotalDue")
oRow = 1
End With

For Each wks In ActiveWorkbook.Worksheets
If wks.Name = newWks.Name Then
'do nothing
Else
oRow = oRow + 1
With wks
newWks.Cells(oRow, "A").Value = .Name
For iCtr = LBound(myAddresses) To UBound(myAddresses)
newWks.Cells(oRow, "A").Offset(0, 1 + iCtr).Value _
= .Range(myAddresses(iCtr)).Value
Next iCtr
End With
End If
Next wks
for iCtr = 2 to Ubound(MyAddresses) + 2
set rng = newWks.Cells(rows.count,iCtr).end(xlup)(2)
rng.FormulaR1C1 = "=Sum(R2C:R[-1]C)"
Next
newWks.Columns.Autofit
End Sub

--
Regards,
Tom Ogilvy

"Rashid Khan" wrote in message
...
Hello All,
Following is the macro posted by Mr. Dave Peterson. It works fine

Option Explicit
Option Base 0
Sub testme2()
Dim newWks As Worksheet
Dim wks As Worksheet
Dim DestCell As Range
Dim RngToCopy As Range
Dim iCtr As Long
Dim myAddresses As Variant
Dim oRow As Long
'billed, balance, due
myAddresses = Array("a55", "a56", "a57")

Set newWks = Worksheets.Add(after:=Worksheets(Worksheets.Count) )

With newWks
.Name = "Cons " & Format(Now, "yyyymmdd_hhmmss")
.Range("a1").Resize(1, 4).Value _
= Array("PartyName", "TotalBilled", "TotalBalance",
"TotalDue")
oRow = 1
End With

For Each wks In ActiveWorkbook.Worksheets
If wks.Name = newWks.Name Then
'do nothing
Else
oRow = oRow + 1
With wks
newWks.Cells(oRow, "A").Value = .Name
For iCtr = LBound(myAddresses) To UBound(myAddresses)
newWks.Cells(oRow, "A").Offset(0, 1 + iCtr).Value
_
= .Range(myAddresses(iCtr)).Value
Next iCtr
End With
End If
Next wks

End Sub
<<<
The macro makes a Consolidated Worksheet (Cons) of all the worksheets.

I
need to have the following changes to take place in the consolidated
worksheet
1) Set the ColumnWidth to Autofit
2) Have the Sum (Total) at the bottom for each Column (starting from B
onwards).

Any suggestions please
TIA
Rashid






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
Dave phlogiston appears in spreadsheet cell when I type Dave P tallsaint Excel Discussion (Misc queries) 2 September 4th 09 11:05 AM
Consolidating sheets Faraz A. Qureshi Excel Discussion (Misc queries) 1 June 22nd 09 08:26 AM
Excel -- Navigation Toolbar for Workbook Sheets -Dave Peterson Brenda Excel Discussion (Misc queries) 13 October 26th 08 08:37 PM
Consolidating all sheets Deepak Excel Discussion (Misc queries) 2 December 29th 06 09:52 PM
Event (BeforeSave) - How to test VBA code? Dave P. can you hear me now? EagleOne Excel Discussion (Misc queries) 3 September 14th 06 07:46 PM


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