Hi guys,
Need help in the below Macro code.
What it does is it filters my master data and then creates new sheet with filtered data and then below filtered data it creates a table with a little formatting.
My query is in the table below being created i wanted to insert a sum of column H beside a value. Also, i wanted to format it even more by creating borders to it. Below is my code.
![]()
Sub MakeSheets() Dim vList 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)" With wsTemp.Cells(Rows.Count, "E").End(xlUp) With .Offset(4).Resize(17) .Interior.ColorIndex = 25 .Font.Color = vbWhite .Font.Bold = True End With .Offset(4) = "FabHotel Name" .Offset(5) = "Period" .Offset(6) = "Actual Room Nights" .Offset(7) = "MG Room Nights" .Offset(8) = "Revenue" .Offset(9) = "Costing" .Offset(10) = "Margins" .Offset(11) = "ARR" .Offset(12) = "Pay at hotel" .Offset(13) = "Prepaid" .Offset(14) = "BTC" .Offset(16) = "Payable for the month of June" .Offset(17) = "Less : Advance Paid on June" .Offset(18) = "Amount Received on Fab EDC Machine" .Offset(19) = "Add- Room Night Purchase Before Agreement" .Offset(20) = "Less : Pay @ Hotel" .Offset(21) = "Payable for the month of june" End With With wsTemp.Cells(Rows.Count, "F").End(xlUp) With .Offset(4).Resize(3) .Interior.ColorIndex = 25 .Font.Color = vbWhite .Font.Bold = True End With .Offset(4) = vList(n) .Offset(5) = "01-06-2016 to 01-07-2016" .Offset(6) = " " End With 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 End Function











LinkBack URL
About LinkBacks
Register To Reply

Bookmarks