putting two VBA's together (novice question)

Scott Law

New Member
Joined
Aug 29, 2011
Messages
12
I had great help with the last six lines of this code on this site, it works great as its own sub but when I added it to an existing VBA it only renames one tab. Any ideas what I am doing wrong when I am combining these two working VBA's.

Code:
Sub Sat_School_Genisis()
'
' Sat_School_Genisis Macro
'

'
    Columns("A:V").Select
    Selection.Delete Shift:=xlToLeft
    Selection.ColumnWidth = 19.67
    Columns("B:B").Select
    Selection.Delete Shift:=xlToLeft
    Columns("D:E").Select
    Selection.Delete Shift:=xlToLeft
    Columns("E:E").Select
    Selection.Delete Shift:=xlToLeft
    Columns("F:L").Select
    Selection.Delete Shift:=xlToLeft
    Columns("E:E").Select
    Selection.Cut Destination:=Columns("F:F")
    Columns("D:D").Select
    Selection.TextToColumns Destination:=Range("D1"), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
        Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _
        :=Array(Array(1, 1), Array(2, 1))
    Columns("E:E").Select
    Selection.Delete Shift:=xlToLeft
    ActiveWindow.SmallScroll Down:=-37

With ActiveSheet
    .AutoFilterMode = False
    With Range("a1", Range("a" & Rows.Count).End(xlUp))
        .AutoFilter 1, 0
        On Error Resume Next
        .Offset(1).SpecialCells(12).EntireRow.Delete
    End With
    .AutoFilterMode = False
End With

Range("A1").Select
    Selection.CurrentRegion.Select
    Selection.Copy
    Sheets.Add
    ActiveSheet.Paste
    Sheets.Add
    ActiveSheet.Paste

   ActiveWindow.SmallScroll Down:=-68
    Sheet1.Select
    Range("A1").Select
    Selection.CurrentRegion.Select
    ActiveWorkbook.Worksheets("34033e21-0dd7-4480-ab77-683d72e").Sort.SortFields. _
        Clear
    ActiveWorkbook.Worksheets("34033e21-0dd7-4480-ab77-683d72e").Sort.SortFields. _
        Add Key:=Range("E2:E631"), SortOn:=xlSortOnValues, Order:=xlAscending, _
        DataOption:=xlSortNormal
    ActiveWorkbook.Worksheets("34033e21-0dd7-4480-ab77-683d72e").Sort.SortFields. _
        Add Key:=Range("D2:D631"), SortOn:=xlSortOnValues, Order:=xlAscending, _
        DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("34033e21-0dd7-4480-ab77-683d72e").Sort
        .SetRange Range("A1:E631")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    ActiveWindow.SmallScroll Down:=-215
    Sheets("Sheet1").Select
    Range("A1").Select
    Selection.CurrentRegion.Select
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("C2:C631") _
        , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Sheet1").Sort
        .SetRange Range("A1:E631")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    Columns("C:C").Select
    Columns("C:C").Cut Destination:=Columns("A:A")
    Columns("C:E").Select
    Selection.Delete Shift:=xlToLeft
    Sheets("Sheet2").Select
    Columns("A:A").Select
    Selection.ClearContents
    Columns("C:F").Select
    Selection.Delete Shift:=xlToLeft
    Range("A1").Select
    ActiveCell.FormulaR1C1 = "Group"
    Range("A2").Select
    ActiveCell.FormulaR1C1 = "PHS-West Saturday School"
    Range("A2").Select
    Selection.AutoFill Destination:=Range("A2:A631")
    Range("A2:A631").Select
    Range("B1").Select
    ActiveCell.FormulaR1C1 = "ReferenceCode"
    Range("C8").Select
    
    ' Sort_by_room Macro
'

'
    Cells.Select
    Sheet1.Sort.SortFields. _
        Clear
    Sheet1.Sort.SortFields. _
        Add Key:=Range("E2:E631"), SortOn:=xlSortOnValues, Order:=xlAscending, _
        DataOption:=xlSortNormal
    Sheet1.Sort.SortFields. _
        Add Key:=Range("D2:D631"), SortOn:=xlSortOnValues, Order:=xlAscending, _
        DataOption:=xlSortNormal
    With Sheet1.Sort
        .SetRange Range("A1:E631")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    

Dim myDate As Date, aDate
myDate = Date + 7 - Weekday(Date)
aDate = Format(myDate, "mm.dd.yyyy")

Sheet1.Name = "Mail Merge" & aDate
Sheet2.Name = "Phone" & aDate
Sheet3.Name = "Roster" & aDate

End Sub
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
I dont know what your first part of the code does
but lets try this

create a new module (go to insert and select module to create a new one)

Sub abDate()
Dim myDate As Date, aDate
myDate = Date + 7 - Weekday(Date)
aDate = Format(myDate, "mm.dd.yyyy")
Sheet1.Name = "Mail Merge" & aDate
Sheet2.Name = "Phone" & aDate
Sheet3.Name = "Roster" & aDate
End Sub

paste the above code in it

replace the above code with Call abDate from you previous code

what this would do is, It will run your first section of the code and then call the second section which is located on module 2
give it a go
 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,248
Members
452,900
Latest member
LisaGo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top