Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-20-2022, 06:55 AM
terryz terryz is offline Need help understanding VBA Windows 10 Need help understanding VBA Office 2016
Novice
Need help understanding VBA
 
Join Date: Aug 2022
Posts: 1
terryz is on a distinguished road
Default Need help understanding VBA

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
Reply With Quote
  #2  
Old 08-20-2022, 11:57 PM
Pecoflyer's Avatar
Pecoflyer Pecoflyer is offline Need help understanding VBA Windows 7 64bit Need help understanding VBA Office 2010
Expert
 
Join Date: Nov 2011
Location: Brussels Belgium
Posts: 2,766
Pecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant future
Default

Hi
you posted in the wrong subforum...
__________________
Did you know you can thank someone who helped you? Click on the tiny scale in the right upper hand corner of your helper's post
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Understanding an Excel formula Joanne Excel 6 05-12-2022 01:00 AM
Need help understanding VBA Understanding SmartArt muna Word 1 10-27-2015 06:39 PM
Need help understanding VBA Understanding Document Corruption Lagrange Word 3 08-03-2015 11:06 AM
Need help understanding VBA Not understanding discrepancies in homework and need help toasty Project 1 07-21-2015 01:06 PM
need help understanding mailmerge code lhuffst Mail Merge 1 02-13-2013 05:19 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:52 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft