Forum Discussion
JoAvg
May 15, 2022Brass Contributor
MACRO - Create Folder/Subfolder based on Today and single cell values - Create *.xlsx in that folder
Hello everyone, newcomer here. I have a book with two main sheets: Overview with ref's to sheet Formulas which is a bunch of index/lookup/search functions. I am in need of two macros in Overview sh...
- May 15, 2022
Sub Macro2() Dim wbkT As Workbook Dim wshS As Worksheet Dim wshT As Worksheet Dim sPath As String Dim sDate As String Dim sCity As String Dim sAddress As String Dim sFile As String Set wshS = ThisWorkbook.Worksheets("Formulas") Set wbkT = Workbooks.Add(xlWBATWorksheet) Set wshT = wbkT.Worksheets(1) wshT.Range("A53:I54").Value = wshS.Range("A53:I54").Value sPath = CreateObject("WScript.Shell").SpecialFolders("Desktop") sDate = Format(Date, "dd mm yyyy") sPath = sPath & "\Delivery\" & sDate sCity = wshS.Range("A5").Value sPath = sPath & "\" & sCity sAddress = wshS.Range("A6").Value sPath = sPath & "\" & sAddress sFile = "Station.xlsx" sPath = sPath & "\" & sFile wbkT.SaveAs Filename:=sPath, FileFormat:=xlOpenXMLWorkbook wbkT.Close End Sub
HansVogelaar
May 15, 2022MVP
Sub Macro2()
Dim wbkT As Workbook
Dim wshS As Worksheet
Dim wshT As Worksheet
Dim sPath As String
Dim sDate As String
Dim sCity As String
Dim sAddress As String
Dim sFile As String
Set wshS = ThisWorkbook.Worksheets("Formulas")
Set wbkT = Workbooks.Add(xlWBATWorksheet)
Set wshT = wbkT.Worksheets(1)
wshT.Range("A53:I54").Value = wshS.Range("A53:I54").Value
sPath = CreateObject("WScript.Shell").SpecialFolders("Desktop")
sDate = Format(Date, "dd mm yyyy")
sPath = sPath & "\Delivery\" & sDate
sCity = wshS.Range("A5").Value
sPath = sPath & "\" & sCity
sAddress = wshS.Range("A6").Value
sPath = sPath & "\" & sAddress
sFile = "Station.xlsx"
sPath = sPath & "\" & sFile
wbkT.SaveAs Filename:=sPath, FileFormat:=xlOpenXMLWorkbook
wbkT.Close
End Sub
- JoAvgMay 15, 2022Brass Contributor
Hello Hans,
If possible, I would like a slight modification to the second code.
The code copies and pastes the range at the same place: i.e. A53:I54.
Any chance it pastes at A1?
Also, if possible, can the formatting also be pasted?
Thank you again.
- HansVogelaarMay 15, 2022MVP
Change the line
wshT.Range("A53:I54").Value = wshS.Range("A53:I54").Value
to
wshS.Range("A53:I54").Copy wshT.Range("A1").PasteSpecial Paste:=xlPasteValues wshT.Range("A1").PasteSpecial Paste:=xlPasteFormats
- JoAvgMay 15, 2022Brass Contributor
- JoAvgMay 15, 2022Brass ContributorThese worked both like a charm.
Thank you a ton!!!- Moneyt71485May 15, 2022Copper ContributorGreat