Hi all, i would to provide me support so that, when i enter in cell "I4" the text "MONTHLY" should hide automatically the entire columns "D" and "E" and when i change the text to "YEARLY" should unhide the columns. Thank you all in advance
lastRow = Range("A" & Rows.Count).End(xlUp).Row
Range("A" & lastRow + 2) = "Total"
Range("A" & lastRow + 3) = "Grand Total"
Range("C" & lastRow + 2) = Application.WorksheetFunction.Sum(Range("C8:C" & lastRow))
Range("C" & lastRow + 3) = Application.WorksheetFunction.Sum(Range("C8:C" & lastRow))
Range("D" & lastRow + 2) = Application.WorksheetFunction.Sum(Range("D8:D" & lastRow))
Range("D" & lastRow + 3) = Application.WorksheetFunction.Sum(Range("D8:D" & lastRow))
Range("E" & lastRow + 2) = Application.WorksheetFunction.Sum(Range("E8:E" & lastRow))
Range("E" & lastRow + 3) = Application.WorksheetFunction.Sum(Range("E8:E" & lastRow))
Range("F" & lastRow + 2) = Application.WorksheetFunction.Sum(Range("F8:F" & lastRow))
Range("F" & lastRow + 3) = Application.WorksheetFunction.Sum(Range("F8:F" & lastRow))
Range("G" & lastRow + 2) = Application.WorksheetFunction.Sum(Range("G8:G" & lastRow))
Range("G" & lastRow + 3) = Application.WorksheetFunction.Sum(Range("G8:G" & lastRow))
Range("H" & lastRow + 2) = Application.WorksheetFunction.Sum(Range("H8:H" & lastRow))
Range("H" & lastRow + 3) = Application.WorksheetFunction.Sum(Range("H8:H" & lastRow))
Range("I" & lastRow + 2) = Application.WorksheetFunction.Sum(Range("I8:I" & lastRow))
Range("I" & lastRow + 3) = Application.WorksheetFunction.Sum(Range("I8:I" & lastRow))
Range("J" & lastRow + 2) = Application.WorksheetFunction.Sum(Range("J8:J" & lastRow))
Range("J" & lastRow + 3) = Application.WorksheetFunction.Sum(Range("J8:J" & lastRow))
Range("K" & lastRow + 2) = Application.WorksheetFunction.Sum(Range("K8:K" & lastRow))
Range("K" & lastRow + 3) = Application.WorksheetFunction.Sum(Range("K8:K" & lastRow))
Range("L" & lastRow + 2) = Application.WorksheetFunction.Sum(Range("L8:L" & lastRow))
Range("L" & lastRow + 3) = Application.WorksheetFunction.Sum(Range("L8:L" & lastRow))
Range("M" & lastRow + 2) = Application.WorksheetFunction.Sum(Range("M8:M" & lastRow))
Range("M" & lastRow + 3) = Application.WorksheetFunction.Sum(Range("M8:M" & lastRow))
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.CountLarge > 1 Then Exit Sub
If Target.Address(0, 0) = "I4" Then
Range("D:E").EntireColumn.Hidden = Target = "MONTHLY"
End If
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.CountLarge > 1 Then Exit Sub
If Target.Address(0, 0) = "I4" Then
Application.EnableEvents = False
Range("D:E").EntireColumn.Hidden = Target = "MONTHLY"
Lastrow = Range("A" & Rows.Count).End(xlUp).Row
Range("A" & Lastrow + 2) = "Total"
Range("A" & Lastrow + 3) = "Grand Total"
Range("C" & Lastrow + 2) = Application.WorksheetFunction.Sum(Range("C8:C" & Lastrow))
Range("C" & Lastrow + 3) = Application.WorksheetFunction.Sum(Range("C8:C" & Lastrow))
Range("D" & Lastrow + 2) = Application.WorksheetFunction.Sum(Range("D8:D" & Lastrow))
Range("D" & Lastrow + 3) = Application.WorksheetFunction.Sum(Range("D8:D" & Lastrow))
Range("E" & Lastrow + 2) = Application.WorksheetFunction.Sum(Range("E8:E" & Lastrow))
Range("E" & Lastrow + 3) = Application.WorksheetFunction.Sum(Range("E8:E" & Lastrow))
Range("F" & Lastrow + 2) = Application.WorksheetFunction.Sum(Range("F8:F" & Lastrow))
Range("F" & Lastrow + 3) = Application.WorksheetFunction.Sum(Range("F8:F" & Lastrow))
Range("G" & Lastrow + 2) = Application.WorksheetFunction.Sum(Range("G8:G" & Lastrow))
Range("G" & Lastrow + 3) = Application.WorksheetFunction.Sum(Range("G8:G" & Lastrow))
Range("H" & Lastrow + 2) = Application.WorksheetFunction.Sum(Range("H8:H" & Lastrow))
Range("H" & Lastrow + 3) = Application.WorksheetFunction.Sum(Range("H8:H" & Lastrow))
Range("I" & Lastrow + 2) = Application.WorksheetFunction.Sum(Range("I8:I" & Lastrow))
Range("I" & Lastrow + 3) = Application.WorksheetFunction.Sum(Range("I8:I" & Lastrow))
Range("J" & Lastrow + 2) = Application.WorksheetFunction.Sum(Range("J8:J" & Lastrow))
Range("J" & Lastrow + 3) = Application.WorksheetFunction.Sum(Range("J8:J" & Lastrow))
Range("K" & Lastrow + 2) = Application.WorksheetFunction.Sum(Range("K8:K" & Lastrow))
Range("K" & Lastrow + 3) = Application.WorksheetFunction.Sum(Range("K8:K" & Lastrow))
Range("L" & Lastrow + 2) = Application.WorksheetFunction.Sum(Range("L8:L" & Lastrow))
Range("L" & Lastrow + 3) = Application.WorksheetFunction.Sum(Range("L8:L" & Lastrow))
Range("M" & Lastrow + 2) = Application.WorksheetFunction.Sum(Range("M8:M" & Lastrow))
Range("M" & Lastrow + 3) = Application.WorksheetFunction.Sum(Range("M8:M" & Lastrow))
Application.EnableEvents = True
End If
End Sub