Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / May 2007

Tip: Looking for answers? Try searching our database.

Combine 2 macros into 1 Please.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Steved - 19 Aug 2005 01:56 GMT
Hello from Steved

Is it possible please to combine the 2 below macros into 1 macro. Thankyou.

Sub AddNameNewSheet2()
   Dim CurrentSheetName As String
   CurrentSheetName = ActiveSheet.Name

   Sheets.Add

   On Error Resume Next
Worksheets.Add.Name = "Waiheke"
Worksheets.Add.Name = "Panmure"
Worksheets.Add.Name = "Swanson"
Worksheets.Add.Name = "Orewa"
Worksheets.Add.Name = "Shore"
Worksheets.Add.Name = "Wiri"
Worksheets.Add.Name = "Papakura"
Worksheets.Add.Name = "Roskill"
Worksheets.Add.Name = "City"
   Do Until Err.Number = 0
       Err.Clear
   Loop
   On Error GoTo 0

   Sheets(CurrentSheetName).Select

End Sub

Sub test4()
Dim rng As Range
Dim WS As Worksheet
   For Each WS In Worksheets
       If WS.Name <> "Audit Report" Then
           Set rng = FilterData(WS.Name)
           If Not rng Is Nothing Then
               rng.Copy WS.Range("A2")
           End If
       End If
   Next WS
End Sub
Private Function FilterData(sCity As String) As Range
Dim cRows As Long
   Range("A1").EntireRow.Insert
   Range("A1").FormulaR1C1 = "temp"
   cRows = Cells(Rows.Count, "A").End(xlUp).Row
   With Columns("A:A")
       .AutoFilter
       .AutoFilter Field:=1, Criteria1:=sCity
   End With
   Set FilterData = Range("A2:A" &
cRows).SpecialCells(xlCellTypeVisible).EntireRow
   Rows("1:1").Delete Shift:=xlUp
End Function
mudraker - 19 Aug 2005 06:05 GMT
Steve

You can combine under 1 macro or have a 3rd macro that calls the othe
2

Sub CallMacros()
Call AddNameNewSheet2
Call test4
End Sub

or

Sub MergedMacro()
Dim CurrentSheetName As String
Dim rng As Range
Dim WS As Worksheet

CurrentSheetName = ActiveSheet.Name

Sheets.Add

On Error Resume Next
Worksheets.Add.Name = "Waiheke"
Worksheets.Add.Name = "Panmure"
Worksheets.Add.Name = "Swanson"
Worksheets.Add.Name = "Orewa"
Worksheets.Add.Name = "Shore"
Worksheets.Add.Name = "Wiri"
Worksheets.Add.Name = "Papakura"
Worksheets.Add.Name = "Roskill"
Worksheets.Add.Name = "City"
Err.Clear
On Error GoTo 0

For Each WS In Worksheets
If WS.Name <> "Audit Report" Then
Set rng = FilterData(WS.Name)
If Not rng Is Nothing Then
rng.Copy WS.Range("A2")
End If
End If
Next WS
End Sub

Private Function FilterData(sCity As String) As Range
Dim cRows As Long
Range("A1").EntireRow.Insert
Range("A1").FormulaR1C1 = "temp"
cRows = Cells(Rows.Count, "A").End(xlUp).Row
With Columns("A:A")
.AutoFilter
.AutoFilter Field:=1, Criteria1:=sCity
End With
Set FilterData = Range("A2:A" _
& cRows).SpecialCells(xlCellTypeVisible).EntireRow
Rows("1:1").Delete Shift:=xlUp
End Functio
Steved - 19 Aug 2005 11:21 GMT
Hello Mudraker thanks.

> Steve
>
[quoted text clipped - 53 lines]
> Rows("1:1").Delete Shift:=xlUp
> End Function
Letzdo_1t - 24 May 2007 18:29 GMT
I spent many hours looking for this.

Much thanks.
James

> Steve
>
[quoted text clipped - 53 lines]
> Rows("1:1").Delete Shift:=xlUp
> End Function
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.