This is the macro that I use. I start the aSetup and it does the rest. I just added your code to it. It did not however close the workbook.
Sub DeleteRow()
'
' DeleteRow Macro
' Start with the data column and delete the entire row
'
'This clears the selected cell
ActiveCell.FormulaR1C1 = ""
'this moves to the next column in the row
ActiveCell.Offset(0, 1).Range("A1").Select
ActiveCell.FormulaR1C1 = ""
Call CopyPaste
ActiveCell.Offset(0, 1).Range("A1").Select
ActiveCell.FormulaR1C1 = ""
Call CopyPaste
ActiveCell.Offset(0, 1).Range("A1").Select
ActiveCell.FormulaR1C1 = ""
Call CopyPaste
'This returns to the first cell that was selected
ActiveCell.Offset(0, -3).Range("A1").Select
End Sub
Sub usedGB()
'
' usedGB Macro
' Calculates the used % and the daily difference and puts the date in the date column
'
'This subtracts the free space from the capacity and tehn divides by the capacity to get the % used
ActiveCell.FormulaR1C1 = "=(R2C-RC[-1])/R2C"
Call CopyPaste
'This goes to the Difference column
ActiveCell.Offset(0, -2).Range("A1").Select
'This subtracts the previous days value from todays value
ActiveCell.FormulaR1C1 = "=RC[2]-R[-1]C[2]"
Call CopyPaste
Call SetFormat
End Sub
Sub ChangeOrder()
'
' ChangeOrder Macro
' switches the order of 2 rows
'
ActiveCell.Range("A1:C1").Select
Selection.Cut
ActiveCell.Offset(0, 4).Range("A1").Select
ActiveSheet.Paste
ActiveCell.Offset(1, -4).Range("A1:C1").Select
Selection.Cut
ActiveCell.Offset(-1, 0).Range("A1").Select
ActiveSheet.Paste
ActiveCell.Offset(0, 4).Range("A1:C1").Select
Selection.Cut
ActiveCell.Offset(1, -4).Range("A1").Select
ActiveSheet.Paste
End Sub
Sub aSetup()
'
' Setup Macro
' deletes the extra space at the begining of the list, sets the formatting, changes the order of the 2 that are out of alpahbetical order,
' copies the numbers from column B to row 2, and inserts the required number of spaces for copying to the Storage Trending workbook
ActiveWindow.DisplayGridlines = True
Range("A3").Select
Selection.Copy
Range("D10").Select
ActiveSheet.Paste
Selection.NumberFormat = "m/d/yyy"
Range("A1").Select
ActiveCell.Range("A1:F7").Select
Selection.Delete shift:=xlUp
ActiveCell.Columns("A:C").EntireColumn.Select
Selection.Style = "Normal"
Selection.Rows.AutoFit
Selection.Columns.AutoFit
ActiveCell.Offset(30, 0).Range("A1").Select
Call ChangeOrder
ActiveCell.Offset(5, 0).Range("A1").Select
Call ChangeOrder
Call CopyShift
Call Insert2Spaces
Call FinishSetup
Call SetFormat
End Sub
Sub CopyShift()
'
' CopyShift Macro
' copies the contents of a column into a row
'
ActiveCell.Offset(11, 2).Range("A1").Select
Range(Selection, Selection.End(xlUp)).Select
Selection.Copy
ActiveWindow.SmallScroll Down:=15
ActiveCell.Offset(2, 3).Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
ActiveCell.Offset(0, 1).Range("A1").Select
End Sub
Sub Insert2Spaces()
'
' Insert2Spaces Macro
' inserts to spaces between the numbers to match the format of the Storage Trending workbook
'
For k = 0 To 47
Selection.Insert shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
ActiveCell.Offset(0, 1).Range("A1").Select
Selection.Insert shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
ActiveCell.Offset(0, 2).Range("A1").Select
Next k
ActiveCell.Offset(0, -147).Range("A1").Select
ActiveCell.Range("A1:EQ1").Select
Selection.Copy
End Sub
Sub CopyPaste()
'
' CopyPaste Macro
' copies the formula from the first cell to the others in the same row 3 cells apart for 48 times
' then goes back to the first cell that was copied
For k = 0 To 47
ActiveCell.Select
Selection.Copy
ActiveCell.Offset(0, 3).Range("A1").Select
ActiveSheet.Paste
Next k
ActiveCell.Offset(0, -144).Range("A1").Select
Application.CutCopyMode = False
End Sub
Sub SetFormat()
'
' SetFormat Macro
' This selects all of the filled cells and does an autofit on them so set the formatting
'
Dim l As Long
Dim lRow As Long
lRow = Sheets("Data").Range("A1").End(xlDown).Row
Sheets("Info").Select
Range("A1:H50").Select
Selection.Columns.AutoFit
Range("A1").Select
Sheets("Data").Select
Range("A1:ER200").Select
Selection.Columns.AutoFit
For l = lRow To 1000 Step 1
If (Range("A" & l).Value) Like "*/20*" Then
Range("A" & l).Select
End If
Next l
End Sub
Sub FinishSetup()
'
'This changes the active workbook and copies everything over to the Storage Trending workbook
'Then it processes the newly copied data and formats everything
Dim l As Long
Dim lRow As Long
Dim wb As Workbook
Selection.Copy
Windows("Storage Trending").Activate
Range("A1").Select
lRow = Sheets("Data").Range("A1000").End(xlUp).Row
For l = lRow To 5 Step -1
Range("A" & l).Select
' Checking for each line till it finds the first empty one
If (Range("A" & l).Value) Like "*" Then
If Range("A" & l + 1).Value Like "" Then
Range("A" & l + 1).Select
Selection.PasteSpecial (xlPasteValues)
ActiveCell.Offset(0, 3).Range("A1").Select
Call usedGB
End If
End If
Next l
Range("A1").Select
For Each wb In Application.Workbooks
If wb.Name Like "Storage_Trending_*" Then
wb.Close savechanges:=True
Exit For
End If
Next wb
End Sub
Bookmarks