VBA copy sheet to new workbook and adding date

hajiali

Active Member
Joined
Sep 8, 2018
Messages
381
Office Version
  1. 2016
Platform
  1. Windows
VBA Code:
Sub ExportEL()
Dim ct As Long, sh As Worksheet, dt As Date
Set sh = ActiveSheet
If Range("AE2") = 1 Then
ct = Day(Application.EoMonth(sh.Range("AD1"), 0))
dt = sh.Range("K1").Value
    For I = 1 To ct
        dt = dt + 1
        Sheets.Add After:=Sheets(Sheets.Count)
        With sh
            Intersect(.UsedRange, .Columns("T:Aw")).Copy ActiveSheet.Range("A1")
        End With
        Sheets(Sheets.Count).Name = Format(dt, "DD")
            Sheets("CSS LOGS").Columns("T:AD").Copy
            Range("A1").Select
           Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
        ActiveSheet.Columns("L:O").Hidden = True
        Range("AD1").Value = DateAdd("D", I, CDate(ActiveCell.Value) - 1)
    Next
    Else: MsgBox "ENTER FIRST DAY OF MONTH", vbOKOnly
    End If
End Sub

Hello everyone. Using the above code I able to Copy the Active sheet From Column(T:AW). when T:AW is copied to new sheets in A1 the date value is in K1 for each sheet. I want the value of each new sheet to and 1 date to previous sheet. I would like to also change the code to instead of coping to new sheet to copy all new sheets to another workbook and name the workbook the name of the Month. Below is a copy of the area that is being copied. any help is greatly apperactied.

Cell Formulas
RangeFormula
T3:T25T3=IFERROR(INDEX('CSS LIST'!$B$2:$B$102,MATCH(AGGREGATE(15,6,'CSS LIST'!$E$2:$E$102,ROW(T1)),'CSS LIST'!$E$2:$E$102,0)),"")
U3:U25U3=IFERROR(INDEX('CSS LIST'!$D$2:$D$102,MATCH(T3,'CSS LIST'!$B$2:$B$102,0)),"")
V3:V25V3=IFERROR(INDEX('CSS LIST'!$C$2:$C$102,MATCH(T3,'CSS LIST'!$B$2:$B$102,0)),"")
X3X3=IFERROR(IF(AE$1=TRUE,INDEX('CSS LOGS'!$D$3:$J$102,MATCH(T3,'CSS LOGS'!$A$3:$A$102,0),MATCH(AH1,'CSS LOGS'!$D$2:$J$2,0)),IF($AF$1=TRUE,INDEX('CSS LOGS'!$L$3:$R$102,MATCH(T3,'CSS LOGS'!$A$3:$A$102,0),MATCH(AH1,'CSS LOGS'!$L$2:$R$2,0)),"")),"")
X4X4=IFERROR(IF(AE$1=TRUE,INDEX('CSS LOGS'!$D$3:$J$102,MATCH(T4,'CSS LOGS'!$A$3:$A$102,0),MATCH(AH1,'CSS LOGS'!$D$2:$J$2,0)),IF($AF$1=TRUE,INDEX('CSS LOGS'!$L$3:$R$102,MATCH(T4,'CSS LOGS'!$A$3:$A$102,0),MATCH(AH1,'CSS LOGS'!$L$2:$R$2,0)),"")),"")
X5X5=IFERROR(IF(AE$1=TRUE,INDEX('CSS LOGS'!$D$3:$J$102,MATCH(T5,'CSS LOGS'!$A$3:$A$102,0),MATCH(AH1,'CSS LOGS'!$D$2:$J$2,0)),IF($AF$1=TRUE,INDEX('CSS LOGS'!$L$3:$R$102,MATCH(T5,'CSS LOGS'!$A$3:$A$102,0),MATCH(AH1,'CSS LOGS'!$L$2:$R$2,0)),"")),"")
X6X6=IFERROR(IF(AE$1=TRUE,INDEX('CSS LOGS'!$D$3:$J$102,MATCH(T6,'CSS LOGS'!$A$3:$A$102,0),MATCH(AH1,'CSS LOGS'!$D$2:$J$2,0)),IF($AF$1=TRUE,INDEX('CSS LOGS'!$L$3:$R$102,MATCH(T6,'CSS LOGS'!$A$3:$A$102,0),MATCH(AH1,'CSS LOGS'!$L$2:$R$2,0)),"")),"")
X7X7=IFERROR(IF(AE$1=TRUE,INDEX('CSS LOGS'!$D$3:$J$102,MATCH(T7,'CSS LOGS'!$A$3:$A$102,0),MATCH(AH1,'CSS LOGS'!$D$2:$J$2,0)),IF($AF$1=TRUE,INDEX('CSS LOGS'!$L$3:$R$102,MATCH(T7,'CSS LOGS'!$A$3:$A$102,0),MATCH(AH1,'CSS LOGS'!$L$2:$R$2,0)),"")),"")
X8X8=IFERROR(IF(AE$1=TRUE,INDEX('CSS LOGS'!$D$3:$J$102,MATCH(T8,'CSS LOGS'!$A$3:$A$102,0),MATCH(AH1,'CSS LOGS'!$D$2:$J$2,0)),IF($AF$1=TRUE,INDEX('CSS LOGS'!$L$3:$R$102,MATCH(T8,'CSS LOGS'!$A$3:$A$102,0),MATCH(AH1,'CSS LOGS'!$L$2:$R$2,0)),"")),"")
X9X9=IFERROR(IF(AE$1=TRUE,INDEX('CSS LOGS'!$D$3:$J$102,MATCH(T9,'CSS LOGS'!$A$3:$A$102,0),MATCH(AH1,'CSS LOGS'!$D$2:$J$2,0)),IF($AF$1=TRUE,INDEX('CSS LOGS'!$L$3:$R$102,MATCH(T9,'CSS LOGS'!$A$3:$A$102,0),MATCH(AH1,'CSS LOGS'!$L$2:$R$2,0)),"")),"")
X10X10=IFERROR(IF(AE$1=TRUE,INDEX('CSS LOGS'!$D$3:$J$102,MATCH(T10,'CSS LOGS'!$A$3:$A$102,0),MATCH(AH1,'CSS LOGS'!$D$2:$J$2,0)),IF($AF$1=TRUE,INDEX('CSS LOGS'!$L$3:$R$102,MATCH(T10,'CSS LOGS'!$A$3:$A$102,0),MATCH(AH1,'CSS LOGS'!$L$2:$R$2,0)),"")),"")
X11X11=IFERROR(IF(AE$1=TRUE,INDEX('CSS LOGS'!$D$3:$J$102,MATCH(T11,'CSS LOGS'!$A$3:$A$102,0),MATCH(AH1,'CSS LOGS'!$D$2:$J$2,0)),IF($AF$1=TRUE,INDEX('CSS LOGS'!$L$3:$R$102,MATCH(T11,'CSS LOGS'!$A$3:$A$102,0),MATCH(AH1,'CSS LOGS'!$L$2:$R$2,0)),"")),"")
X12X12=IFERROR(IF(AE$1=TRUE,INDEX('CSS LOGS'!$D$3:$J$102,MATCH(T12,'CSS LOGS'!$A$3:$A$102,0),MATCH(AH1,'CSS LOGS'!$D$2:$J$2,0)),IF($AF$1=TRUE,INDEX('CSS LOGS'!$L$3:$R$102,MATCH(T12,'CSS LOGS'!$A$3:$A$102,0),MATCH(AH1,'CSS LOGS'!$L$2:$R$2,0)),"")),"")
X13X13=IFERROR(IF(AE$1=TRUE,INDEX('CSS LOGS'!$D$3:$J$102,MATCH(T13,'CSS LOGS'!$A$3:$A$102,0),MATCH(AH1,'CSS LOGS'!$D$2:$J$2,0)),IF($AF$1=TRUE,INDEX('CSS LOGS'!$L$3:$R$102,MATCH(T13,'CSS LOGS'!$A$3:$A$102,0),MATCH(AH1,'CSS LOGS'!$L$2:$R$2,0)),"")),"")
X14X14=IFERROR(IF(AE$1=TRUE,INDEX('CSS LOGS'!$D$3:$J$102,MATCH(T14,'CSS LOGS'!$A$3:$A$102,0),MATCH(AH1,'CSS LOGS'!$D$2:$J$2,0)),IF($AF$1=TRUE,INDEX('CSS LOGS'!$L$3:$R$102,MATCH(T14,'CSS LOGS'!$A$3:$A$102,0),MATCH(AH1,'CSS LOGS'!$L$2:$R$2,0)),"")),"")
X15X15=IFERROR(IF(AE$1=TRUE,INDEX('CSS LOGS'!$D$3:$J$102,MATCH(T15,'CSS LOGS'!$A$3:$A$102,0),MATCH(AH1,'CSS LOGS'!$D$2:$J$2,0)),IF($AF$1=TRUE,INDEX('CSS LOGS'!$L$3:$R$102,MATCH(T15,'CSS LOGS'!$A$3:$A$102,0),MATCH(AH1,'CSS LOGS'!$L$2:$R$2,0)),"")),"")
X16X16=IFERROR(IF(AE$1=TRUE,INDEX('CSS LOGS'!$D$3:$J$102,MATCH(T16,'CSS LOGS'!$A$3:$A$102,0),MATCH(AH1,'CSS LOGS'!$D$2:$J$2,0)),IF($AF$1=TRUE,INDEX('CSS LOGS'!$L$3:$R$102,MATCH(T16,'CSS LOGS'!$A$3:$A$102,0),MATCH(AH1,'CSS LOGS'!$L$2:$R$2,0)),"")),"")
X17X17=IFERROR(IF(AE$1=TRUE,INDEX('CSS LOGS'!$D$3:$J$102,MATCH(T17,'CSS LOGS'!$A$3:$A$102,0),MATCH(AH1,'CSS LOGS'!$D$2:$J$2,0)),IF($AF$1=TRUE,INDEX('CSS LOGS'!$L$3:$R$102,MATCH(T17,'CSS LOGS'!$A$3:$A$102,0),MATCH(AH1,'CSS LOGS'!$L$2:$R$2,0)),"")),"")
X18X18=IFERROR(IF(AE$1=TRUE,INDEX('CSS LOGS'!$D$3:$J$102,MATCH(T18,'CSS LOGS'!$A$3:$A$102,0),MATCH(AH1,'CSS LOGS'!$D$2:$J$2,0)),IF($AF$1=TRUE,INDEX('CSS LOGS'!$L$3:$R$102,MATCH(T18,'CSS LOGS'!$A$3:$A$102,0),MATCH(AH1,'CSS LOGS'!$L$2:$R$2,0)),"")),"")
X19X19=IFERROR(IF(AE$1=TRUE,INDEX('CSS LOGS'!$D$3:$J$102,MATCH(T19,'CSS LOGS'!$A$3:$A$102,0),MATCH(AH1,'CSS LOGS'!$D$2:$J$2,0)),IF($AF$1=TRUE,INDEX('CSS LOGS'!$L$3:$R$102,MATCH(T19,'CSS LOGS'!$A$3:$A$102,0),MATCH(AH1,'CSS LOGS'!$L$2:$R$2,0)),"")),"")
X20X20=IFERROR(IF(AE$1=TRUE,INDEX('CSS LOGS'!$D$3:$J$102,MATCH(T20,'CSS LOGS'!$A$3:$A$102,0),MATCH(AH1,'CSS LOGS'!$D$2:$J$2,0)),IF($AF$1=TRUE,INDEX('CSS LOGS'!$L$3:$R$102,MATCH(T20,'CSS LOGS'!$A$3:$A$102,0),MATCH(AH1,'CSS LOGS'!$L$2:$R$2,0)),"")),"")
X21X21=IFERROR(IF(AE$1=TRUE,INDEX('CSS LOGS'!$D$3:$J$102,MATCH(T21,'CSS LOGS'!$A$3:$A$102,0),MATCH(AH1,'CSS LOGS'!$D$2:$J$2,0)),IF($AF$1=TRUE,INDEX('CSS LOGS'!$L$3:$R$102,MATCH(T21,'CSS LOGS'!$A$3:$A$102,0),MATCH(AH1,'CSS LOGS'!$L$2:$R$2,0)),"")),"")
X22X22=IFERROR(IF(AE$1=TRUE,INDEX('CSS LOGS'!$D$3:$J$102,MATCH(T22,'CSS LOGS'!$A$3:$A$102,0),MATCH(AH1,'CSS LOGS'!$D$2:$J$2,0)),IF($AF$1=TRUE,INDEX('CSS LOGS'!$L$3:$R$102,MATCH(T22,'CSS LOGS'!$A$3:$A$102,0),MATCH(AH1,'CSS LOGS'!$L$2:$R$2,0)),"")),"")
X23X23=IFERROR(IF(AE$1=TRUE,INDEX('CSS LOGS'!$D$3:$J$102,MATCH(T23,'CSS LOGS'!$A$3:$A$102,0),MATCH(AH1,'CSS LOGS'!$D$2:$J$2,0)),IF($AF$1=TRUE,INDEX('CSS LOGS'!$L$3:$R$102,MATCH(T23,'CSS LOGS'!$A$3:$A$102,0),MATCH(AH1,'CSS LOGS'!$L$2:$R$2,0)),"")),"")
X24X24=IFERROR(IF(AE$1=TRUE,INDEX('CSS LOGS'!$D$3:$J$102,MATCH(T24,'CSS LOGS'!$A$3:$A$102,0),MATCH(AH1,'CSS LOGS'!$D$2:$J$2,0)),IF($AF$1=TRUE,INDEX('CSS LOGS'!$L$3:$R$102,MATCH(T24,'CSS LOGS'!$A$3:$A$102,0),MATCH(AH1,'CSS LOGS'!$L$2:$R$2,0)),"")),"")
X25X25=IFERROR(IF(AE$1=TRUE,INDEX('CSS LOGS'!$D$3:$J$102,MATCH(T25,'CSS LOGS'!$A$3:$A$102,0),MATCH(AH1,'CSS LOGS'!$D$2:$J$2,0)),IF($AF$1=TRUE,INDEX('CSS LOGS'!$L$3:$R$102,MATCH(T25,'CSS LOGS'!$A$3:$A$102,0),MATCH(AH1,'CSS LOGS'!$L$2:$R$2,0)),"")),"")
Named Ranges
NameRefers ToCells
'CSS LOGS'!Print_Area='CSS LOGS'!$T$1:$AD$102T3
Cells with Conditional Formatting
CellConditionCell FormatStop If True
X3:X102Cell Valuecontains "OFF"textNO
 

Some videos you may like

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Watch MrExcel Video

Forum statistics

Threads
1,126,888
Messages
5,621,422
Members
415,839
Latest member
Pollydooner

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
Top