![]() |
#1
|
|||
|
|||
![]()
Hello people of the MS forum,
Need a help understanding and applying it to different workbooks. The below VBA was given to me by my predecessor and didn't leave too much details on how to write the script. I'm not good at VBA by any stretch but my manager wants me to mimic the same using a different newly created workbook. I tried copying the script but can't make it do the same. Sub Copy_Sheets_To_New_Workbook() Dim wb As Workbook, sh As Worksheet, DateString, D, Value, Act As String Dim Path As Variant, L, x As Long Application.ScreenUpdating = False Set wb = ThisWorkbook Path = ThisWorkbook.Path & "" Value = wb.Sheets("Raw Data").Cells(1, 1) DateString = Left(Right(Value, 18), 2) & "-" & Left(Right(Value, 15), 2) & "-" & Left(Right(Value, 12), 2) 'Copy specified sheets to new workbooks For L = 1 To 6 wb.Activate Set sh = Worksheets(L) sh.Select Application.CutCopyMode = False sh.Copy Cells.Select Selection.Copy Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Act = sh.Cells(1, 1) ActiveWorkbook.SaveAs Filename:= _ Path & "MTD - " & Act & " " & DateString & ".xlsx", FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False Next L wb.Activate ActiveWorkbook.SaveAs Filename:= _ Path & "MTD - " & DateString & ".xlsx", FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False Application.ScreenUpdating = True End Sub |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Understanding an Excel formula | Joanne | Excel | 6 | 05-12-2022 01:00 AM |
![]() |
muna | Word | 1 | 10-27-2015 06:39 PM |
![]() |
Lagrange | Word | 3 | 08-03-2015 11:06 AM |
![]() |
toasty | Project | 1 | 07-21-2015 01:06 PM |
need help understanding mailmerge code | lhuffst | Mail Merge | 1 | 02-13-2013 05:19 PM |