VBA splitting worksheet to multiple worksheets with formula

kbghud

New Member
Joined
Feb 13, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi,

New to the forum. I have a macro that splits one worksheet into multiple worksheets and it works great with one exception. I have a formula in Column R that I need to go into every new sheet. I have the macro splitting the worksheet based on the value of column B. It puts the formula on the new worksheet for 6, but does not do it for any other worksheet. Can anyone help me out? If anyone has a suggestion for getting it to stop creating the "blank" worksheet before 6 I'd appreciate that as well, but it's not a necessity. Thank you!

Sub Review()
'
' Review Macro
' Next Review Date
'
' Keyboard Shortcut: Ctrl+r
'
Columns("A:O").Select
Range("A2").Activate
Columns("A:O").EntireColumn.AutoFit
ActiveWindow.SmallScroll ToRight:=-6
Range("B3").Select
Dim lr As Long
Dim ws As Worksheet
Dim vcol, i As Integer
Dim icol As Long
Dim myarr As Variant
Dim title As String
Dim titlerow As Integer
vcol = 2
Set ws = Sheets("Sheet1")
lr = ws.Cells(ws.Rows.Count, vcol).End(xlUp).Row
title = "A2:T2"
titlerow = 1
icol = ws.Columns.Count
ws.Cells(1, icol) = "Unique"
For i = 2 To lr
On Error Resume Next
If ws.Cells(i, vcol) <> "" And Application.WorksheetFunction.Match(ws.Cells(i, vcol), ws.Columns(icol), 0) = 0 Then
ws.Cells(ws.Rows.Count, icol).End(xlUp).Offset(1) = ws.Cells(i, vcol)
End If
Next
myarr = Application.WorksheetFunction.Transpose(ws.Columns(icol).SpecialCells(xlCellTypeConstants))
ws.Columns(icol).Clear
For i = 2 To UBound(myarr)
ws.Range(title).AutoFilter field:=vcol, Criteria1:=myarr(i) & ""
If Not Evaluate("=ISREF('" & myarr(i) & "'!A1)") Then
Sheets.Add(after:=Worksheets(Worksheets.Count)).Name = myarr(i) & ""
Else
Sheets(myarr(i) & "").Move after:=Worksheets(Worksheets.Count)
End If
ws.Range("A" & titlerow & ":A" & lr).EntireRow.Copy Sheets(myarr(i) & "").Range("A1")
Sheets(myarr(i) & "").Columns.AutoFit
Next
ws.AutoFilterMode = False
ws.Activate
End Sub


Reviews.xlsx
ABCDEFGHIJKLMNOPQRST
1February 2022 Hourly Employee Review Spreadsheet
2LocationPropertyAssignment NumberEmpIDLast NameFirst NameJob TitleStart DateService DateLast Incr DtCurrent RateNext ReviewReviewerReviewer NameTypeEffective Date New Hourly Biweekly/ Weekly Rate % of rate changeCommentsNext Review Date
30006 - Jacksonville Beach Courtyard0006E728745728745Bass ChristopherEngineer9/11/20219/11/20211512/11/2021449851Billy HopsonH-100.000%
40006 - Jacksonville Beach Courtyard0006E728844728844Caicedo StephanieAM Server9/27/20219/27/202110726508William RienksH-100.000%
50006 - Jacksonville Beach Courtyard0006E728844-2728844Caicedo StephanieAM Cashier9/27/20219/27/202112726508William RienksH-100.000%
60006 - Jacksonville Beach Courtyard0006E728844-3728844Caicedo StephanieLounge Bartender9/27/20219/27/20218726508William RienksH-100.000%
70006 - Jacksonville Beach Courtyard0006E729036729036Pak VladimirEngineer10/11/202110/11/2021181/13/2022449851Billy HopsonH-100.000%
80065 - Durham Marriott0065E431435-3431435Flores VictorLine Cook10/31/20219/19/200610/31/2021182/1/2022725945Ruben VeraH-100.000%
90065 - Durham Marriott0065E460447-10460447Darden TinaBellperson10/24/202110/30/2021141/1/2022435620Alex ReitterH-100.000%
100065 - Durham Marriott0065E460447-11460447Darden TinaConcierge10/24/202110/30/2021161/1/2022435620Alex ReitterH-100.000%
110065 - Durham Marriott0065E460447-8460447Darden TinaLine Cook10/24/202110/24/2021161/1/2022435620Alex ReitterH-100.000%
120065 - Durham Marriott0065E460447-9460447Darden TinaAM Server10/24/202110/30/2021131/1/2022435620Alex ReitterH-100.000%
130065 - Durham Marriott0065E728677728677Alston EmmanuelDishwasher9/11/20219/11/20211312/1/2021435620Alex ReitterH-100.000%
140065 - Durham Marriott0065E728694728694Cohen AndrewLine Cook9/15/20219/15/20211612/1/2021435620Alex ReitterH-100.000%
150065 - Durham Marriott0065E728826728826Brown WesleyEngineer9/23/20219/23/20211712/1/202165060Robert GrissomH-100.000%
160065 - Durham Marriott0065E728985728985Richardson SybilFront Desk Agent10/11/202110/11/2021141/1/2022725945Ruben VeraH-100.000%
170065 - Durham Marriott0065E729008729008Mason NasiaFront Desk Agent10/11/202110/11/2021141/1/2022725945Ruben VeraH-100.000%
180065 - Durham Marriott0065E729068729068Jackson DeAntwonSecurity Guard10/14/202110/14/2021141/1/2022725945Ruben VeraH-100.000%
190065 - Durham Marriott0065E729068-2729068Jackson DeAntwonBellperson10/14/202111/14/2021141/1/2022725945Ruben VeraH-100.000%
200065 - Durham Marriott0065E729074729074Mason KaylaLounge Bartender10/14/202110/14/2021101/1/2022435620Alex ReitterH-100.000%
210065 - Durham Marriott0065E729169729169Whaley HermonSecurity Guard10/21/202110/21/2021141/1/2022435620Alex ReitterH-100.000%
220065 - Durham Marriott0065E729375729375McCray Jr WilliamLine Cook11/3/202111/3/2021162/3/2022435620Alex ReitterH-100.000%
230065 - Durham Marriott0065E729420729420Harris KaylahLounge Bartender11/5/202111/5/20211065008Sharon WilliamsH-100.000%
240072 - Newport Harbor Hotel0072E729648729648Mullen DavidNight Auditor11/23/202111/23/2021162/23/2022720859Ian LegrosH-100.000%
250075 - Edina Residence Inn0075E729628729628Vargas AliciaGuest Room Attendant11/23/202111/23/2021152/23/2022412510Jose Tapia Jr.H-100.000%
260075 - Edina Residence Inn0075E729634729634Rosas Martinez JuanaGuest Room Attendant11/23/202111/23/2021152/23/2022412510Jose Tapia Jr.H-100.000%
270079 - State College Holiday Exp0079E428035-4428035Garis KarenGuest Room Attendant3/7/20212/13/20188/21/2021152/13/2022442670Laurel StewartH-100.000%
280079 - State College Holiday Exp0079E451643-4451643Norris MarthaHousekeeping Supervisor5/23/20201/12/20128/21/2021171/12/2022442670Laurel StewartH-100.000%
290079 - State College Holiday Exp0079E462323-3462323Hill TimothyEngineer5/19/20212/5/20188/21/202117.752/5/202279003Ronald McElfreshH-100.000%
300079 - State College Holiday Exp0079E728855728855St Juste AdiaFront Desk Agent9/22/20219/22/202114726345Mary SullivanH-100.000%
310080 - State College Hampton Inn0080E462179-3462179Luse AbagaelFront Desk Agent5/29/20201/8/20188/21/202115.51/8/2022458190Pamela NewberryH-100.000%
320080 - State College Hampton Inn0080E464671-3464671Offutt TaraRm Inspector/Inspectress6/4/20202/25/20198/21/2021162/25/2022458190Pamela NewberryH-100.000%
330080 - State College Hampton Inn0080E729300729300Getgen ToraGuest Room Attendant10/25/202110/25/2021161/25/2022458190Pamela NewberryH-100.000%
340084 - Charleston Holiday Inn Exp0084E728717728717Browning MarthaFloor Houseperson9/11/20219/11/20211012/12/2021460433Terri MitchellH-100.000%
350084 - Charleston Holiday Inn Exp0084E728925728925McBride JamieGuest Room Attendant10/2/202110/2/2021111/4/2022460433Terri MitchellH-100.000%
360084 - Charleston Holiday Inn Exp0084E729301729301Tellis TahjeGuest Room Attendant10/28/202110/28/2021111/28/2022460433Terri MitchellH-100.000%
370087 - Courtyard Newark At Ud0087E450164-5450164Chambers JessicaLounge Bartender5/21/20212/5/20115/21/202110.632/5/2022452825Joseph FotiH-100.000%
380087 - Courtyard Newark At Ud0087E729513729513Hagan ReidBanquet Server11/16/202111/16/202162/14/2022423267Dawn AckermanH-100.000%
Sheet1
Cell Formulas
RangeFormula
B3:B38B3=LEFT(A3,4)
R3:R38R3=((Q3-K3)/K3)
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Hi,​
do you need to keep the formulas in the destination sheets or just the values ?​
 
Upvote 0
The formulas should carry over to all of the destination sheets.
 
Upvote 0
According to your attachment a VBA demonstration for starters like any Excel user operating manually :​
VBA Code:
Sub Demo1()
        Const S = "Sheet1"
        Dim Ws As Worksheet, L&, V, R&
    With Application
        .DisplayAlerts = False
        .ScreenUpdating = False
    For Each Ws In Worksheets
          If Ws.Name <> S Then Ws.Delete
    Next
    With Sheets(S).[A1].CurrentRegion
            L = .Rows.Count
            .Range("B2:B" & L).AdvancedFilter 2, , .Range("Z1"), True
            With .Range("Z1").CurrentRegion:  V = .Value2:  .Clear:  End With
        For R = UBound(V) To 2 Step -1
                .Parent.Copy , .Parent
            With ActiveSheet
                .Name = V(R, 1)
                .Range("A2:A" & L).AutoFilter 1, "<>" & V(R, 1) & "*"
                .Rows("3:" & L).Delete
                .[A2].AutoFilter
            End With
        Next
    End With
        .DisplayAlerts = True
        .ScreenUpdating = True
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,286
Members
452,631
Latest member
a_potato

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