Hi guys,
Need help in simplifying the below macro.
This macro basically filters the data and copies the filtered data into a new sheet. Then below the filtered data it creates a table which is common in all the sheets created.
I need help where after the table is created i need to copy a value from the data above.
Need help in simplifying the below macro.
This macro basically filters the data and copies the filtered data into a new sheet. Then below the filtered data it creates a table which is common in all the sheets created.
I need help where after the table is created i need to copy a value from the data above.
Code:
[COLOR=#333333]Sub MakeSheets() Dim vList[/COLOR] Dim n As Long
Dim rgData As Range
Dim wsTemp As Worksheet
Application.ScreenUpdating = False
With ActiveSheet
.AutoFilterMode = False
Set rgData = .Range("C1:C" & .Cells(.Rows.Count, "C").End(xlUp).Row)
vList = GetUniqueList(rgData.Offset(1).Resize(rgData.Rows.Count - 1))
For n = LBound(vList) To UBound(vList)
Set wsTemp = Sheets.Add
wsTemp.Name = vList(n)
rgData.AutoFilter field:=1, Criteria1:=vList(n)
.UsedRange.Copy wsTemp.Cells(1)
wsTemp.Cells(Rows.Count, "H").End(xlUp).Offset(1).FormulaR1C1 = "=SUM(R2C:R[-1]C)"
wsTemp.Cells(Rows.Count, "AQ").End(xlUp).Offset(1).FormulaR1C1 = "=SUM(R2C:R[-1]C)"
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(4).FormulaR1C1 = "FabHotel Name"
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Interior.ColorIndex = 25
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Font.Color = vbWhite
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Font.Bold = True
wsTemp.Cells(Rows.Count, "F").End(xlUp).Offset(4).FormulaR1C1 = vList(n)
wsTemp.Cells(Rows.Count, "F").End(xlUp).Offset(0).Interior.ColorIndex = 25
wsTemp.Cells(Rows.Count, "F").End(xlUp).Offset(0).Font.Color = vbWhite
wsTemp.Cells(Rows.Count, "F").End(xlUp).Offset(0).Font.Bold = True
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(1).FormulaR1C1 = "Period"
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Interior.ColorIndex = 25
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Font.Color = vbWhite
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Font.Bold = True
wsTemp.Cells(Rows.Count, "F").End(xlUp).Offset(1).FormulaR1C1 = "01-06-2016 to 01-07-2016"
wsTemp.Cells(Rows.Count, "F").End(xlUp).Offset(0).Interior.ColorIndex = 25
wsTemp.Cells(Rows.Count, "F").End(xlUp).Offset(0).Font.Color = vbWhite
wsTemp.Cells(Rows.Count, "F").End(xlUp).Offset(0).Font.Bold = True
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(1).FormulaR1C1 = "Actual Room Nights"
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Interior.ColorIndex = 25
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Font.Color = vbWhite
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Font.Bold = True
wsTemp.Cells(Rows.Count, "F").End(xlUp).Offset(1).FormulaR1C1 = " "
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(1).FormulaR1C1 = "MG Room Nights"
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Interior.ColorIndex = 25
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Font.Color = vbWhite
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Font.Bold = True
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(1).FormulaR1C1 = "Revenue"
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Interior.ColorIndex = 25
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Font.Color = vbWhite
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Font.Bold = True
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(1).FormulaR1C1 = "Costing"
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Interior.ColorIndex = 25
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Font.Color = vbWhite
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Font.Bold = True
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(1).FormulaR1C1 = "Margins"
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Interior.ColorIndex = 25
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Font.Color = vbWhite
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Font.Bold = True
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(1).FormulaR1C1 = "ARR"
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Interior.ColorIndex = 25
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Font.Color = vbWhite
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Font.Bold = True
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(1).FormulaR1C1 = "Pay at hotel"
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Interior.ColorIndex = 25
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Font.Color = vbWhite
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Font.Bold = True
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(1).FormulaR1C1 = "Prepaid"
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Interior.ColorIndex = 25
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Font.Color = vbWhite
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Font.Bold = True
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(1).FormulaR1C1 = "BTC"
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Interior.ColorIndex = 25
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Font.Color = vbWhite
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Font.Bold = True
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(2).FormulaR1C1 = "Payable for the month of June"
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Interior.ColorIndex = 25
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Font.Color = vbWhite
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Font.Bold = True
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(1).FormulaR1C1 = "Less : Advance Paid on June"
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Interior.ColorIndex = 25
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Font.Color = vbWhite
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Font.Bold = True
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(1).FormulaR1C1 = "Amount Received on Fab EDC Machine"
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Interior.ColorIndex = 25
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Font.Color = vbWhite
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Font.Bold = True
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(1).FormulaR1C1 = "Less : Pay @ Hotel"
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Interior.ColorIndex = 25
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Font.Color = vbWhite
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Font.Bold = True
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(1).FormulaR1C1 = "Add- Room Night Purchase Before Agreement"
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Interior.ColorIndex = 25
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Font.Color = vbWhite
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Font.Bold = True
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(1).FormulaR1C1 = "Payable for the month of june"
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Interior.ColorIndex = 25
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Font.Color = vbWhite
wsTemp.Cells(Rows.Count, "E").End(xlUp).Offset(0).Font.Bold = True
Columns("E").ColumnWidth = 35
Columns("F").ColumnWidth = 25
Next n
.AutoFilterMode = False
End With
Application.ScreenUpdating = False
End Sub
Public Function GetUniqueList(rgData As Range) As Variant
Dim dic As Object
Dim x As Long
Dim y As Long
Dim data As Variant
If rgData.Count = 1 Then
GetUniqueList = Array(rgData.Value2)
Else
Set dic = CreateObject("Scripting.Dictionary")
data = rgData.Value2
For x = 1 To UBound(data, 1)
For y = 1 To UBound(data, 2)
dic(data(x, y)) = Empty
Next y
Next x
GetUniqueList = dic.keys
End If [COLOR=#333333]End Function[/COLOR]