CRVerdusco
New Member
- Joined
- Nov 22, 2013
- Messages
- 6
I am trying to get a workbook_Sheetchange with a select case to work on multiple spreadsheets. I had a similar code working just fine in each worksheet but felt like it was bogging down too much, I am trying to streamline better.
The workbook has a sheet for every day of the month and then a monthly totals sheet at the end that calls from each of the daily sheets. The select case applies specific formulas and formatting based on the billing code placed in Column "A"
Any help or feedback would be appreciated. I was also curious if I could call macros for each case to if that would be better.
I don't know if it's an option we have 7 different properties that use a different workbook each, we also have an add-in bar created could the custom formulas and sheetchange be in the add-in while calling constants from a module in each individual workbook?
The workbook has a sheet for every day of the month and then a monthly totals sheet at the end that calls from each of the daily sheets. The select case applies specific formulas and formatting based on the billing code placed in Column "A"
Any help or feedback would be appreciated. I was also curious if I could call macros for each case to if that would be better.
I don't know if it's an option we have 7 different properties that use a different workbook each, we also have an add-in bar created could the custom formulas and sheetchange be in the add-in while calling constants from a module in each individual workbook?
Code:
Private Sub Workbook_SheetChange(ByVal sh As Object, ByVal Target As Range)
Application.EnableEvents = False
If Target.Cells.Count = 1 Then
If Not Intersect(Target, ActiveSheet.Range("A:A")) Is Nothing Then
Select Case Target
Case "C", "c" ' COMPLIMENTARY ERROR '
MsgBox "Please enter a more descriptive Complimentary Code", , "COMPLIMENTARY CODE ERROR"
ActiveSheet.Range("M" & Target.Row).Font.ColorIndex = 0
ActiveSheet.Range("Q" & Target.Row).Value = "ERROR"
ActiveSheet.Range("Q" & Target.Row).Interior.ColorIndex = 3
ActiveSheet.Range("R" & Target.Row).FormulaR1C1 = "=equipSUB(rc[-5],rc[-3],rc[-2])"
ActiveSheet.Range("U" & Target.Row).Value = "ERROR"
ActiveSheet.Range("U" & Target.Row).Interior.ColorIndex = 3
ActiveSheet.Range("V" & Target.Row) = ""
ActiveSheet.Range("W" & Target.Row) = ""
ActiveSheet.Range("X" & Target.Row) = ""
ActiveSheet.Range("Y" & Target.Row) = ""
ActiveSheet.Range("Z" & Target.Row) = ""
ActiveSheet.Range("AA" & Target.Row) = ""
Case "CO", "co", "Co", "cO" ' COMPLIMENTARY OTHER EQUIPMENT '
ActiveSheet.Range("M" & Target.Row).Font.ColorIndex = 45
ActiveSheet.Range("Q" & Target.Row).FormulaR1C1 = "=svcC(rc[-4]:rc[-3])"
ActiveSheet.Range("Q" & Target.Row).Interior.ColorIndex = xlColorIndexNone
ActiveSheet.Range("R" & Target.Row).FormulaR1C1 = "=equipSUB(rc[-5],rc[-3],rc[-2])"
ActiveSheet.Range("U" & Target.Row).Value = "COMP-O"
ActiveSheet.Range("U" & Target.Row).Interior.ColorIndex = 45
ActiveSheet.Range("V" & Target.Row).FormulaR1C1 = "=AVTotal(rc[-4]:rc[-1])"
ActiveSheet.Range("W" & Target.Row).Value = "COMP-O"
ActiveSheet.Range("X" & Target.Row) = ""
ActiveSheet.Range("Y" & Target.Row) = ""
ActiveSheet.Range("Z" & Target.Row).FormulaR1C1 = "=CompO((rc[-9],rc[-11],rc[-13]),(rc[-10],rc[-6]))"
ActiveSheet.Range("AA" & Target.Row) = ""
Case "CI", "ci", "Ci", "cI" ' COMPLIMENTARY INTERNET '
ActiveSheet.Range("M" & Target.Row).Font.ColorIndex = 41
ActiveSheet.Range("Q" & Target.Row).FormulaR1C1 = "=svcC(rc[-4]:rc[-3])"
ActiveSheet.Range("Q" & Target.Row).Interior.ColorIndex = xlColorIndexNone
ActiveSheet.Range("R" & Target.Row).FormulaR1C1 = "=equipSUB(rc[-5],rc[-3],rc[-2])"
ActiveSheet.Range("U" & Target.Row).Value = "COMP-I"
ActiveSheet.Range("U" & Target.Row).Interior.ColorIndex = 41
ActiveSheet.Range("V" & Target.Row).FormulaR1C1 = "=AVTotal(rc[-4]:rc[-1])"
ActiveSheet.Range("W" & Target.Row).Value = "COMP-I"
ActiveSheet.Range("X" & Target.Row) = ""
ActiveSheet.Range("Y" & Target.Row).FormulaR1C1 = "=CompI(rc[-5]:rc[-8])"
ActiveSheet.Range("Z" & Target.Row) = ""
ActiveSheet.Range("AA" & Target.Row) = ""
Case "CD", "cd", "Cd", "cD" ' COMPLIMENTARY DISCOUNT '
ActiveSheet.Range("M" & Target.Row).Font.ColorIndex = 41
ActiveSheet.Range("Q" & Target.Row).Value = "COMP-D"
ActiveSheet.Range("Q" & Target.Row).Interior.ColorIndex = 41
ActiveSheet.Range("R" & Target.Row).FormulaR1C1 = "=equipDiscSUB(rc[-5],rc[-3],rc[-2])"
ActiveSheet.Range("U" & Target.Row).Value = "COMP-D"
ActiveSheet.Range("U" & Target.Row).Interior.ColorIndex = 41
ActiveSheet.Range("V" & Target.Row).FormulaR1C1 = "=AVTotal(rc[-4]:rc[-1])"
ActiveSheet.Range("W" & Target.Row).Value = "COMP-D"
ActiveSheet.Range("X" & Target.Row) = ""
ActiveSheet.Range("Y" & Target.Row) = ""
ActiveSheet.Range("Z" & Target.Row).FormulaR1C1 = "=CompD((rc[-9],rc[-11],rc[-13],rc[-7]),(rc[-10],rc[-6]))"
ActiveSheet.Range("AA" & Target.Row) = ""
Case "E", "e" ' TAX EXEMPT '
ActiveSheet.Range("M" & Target.Row).Font.ColorIndex = 0
ActiveSheet.Range("Q" & Target.Row).FormulaR1C1 = "=svcC(rc[-4]:rc[-3])"
ActiveSheet.Range("Q" & Target.Row).Interior.ColorIndex = xlColorIndexNone
ActiveSheet.Range("R" & Target.Row).FormulaR1C1 = "=equipSUB(rc[-5],rc[-3],rc[-2])"
ActiveSheet.Range("U" & Target.Row).Value = "EXEMPT"
ActiveSheet.Range("U" & Target.Row).Interior.ColorIndex = 4
ActiveSheet.Range("V" & Target.Row).FormulaR1C1 = "=AVTotal(rc[-4]:rc[-1])"
ActiveSheet.Range("W" & Target.Row).FormulaR1C1 = "=HAVS(rc[-2]:rc[-5])"
ActiveSheet.Range("X" & Target.Row).FormulaR1C1 = "=Hotel(rc[-3]:rc[-6])"
ActiveSheet.Range("Y" & Target.Row) = ""
ActiveSheet.Range("Z" & Target.Row) = ""
ActiveSheet.Range("AA" & Target.Row).FormulaR1C1 = "=Tax(rc[-7]:rc[-9])"
Case "D", "d" ' DISCOUNT '
ActiveSheet.Range("M" & Target.Row).Font.ColorIndex = 0
ActiveSheet.Range("Q" & Target.Row).Value = "DISC"
ActiveSheet.Range("Q" & Target.Row).Interior.ColorIndex = 44
ActiveSheet.Range("R" & Target.Row).FormulaR1C1 = "=equipDiscSUB(rc[-5],rc[-3],rc[-2])"
ActiveSheet.Range("U" & Target.Row).FormulaR1C1 = "=Tax(rc[-1]:rc[-3])"
ActiveSheet.Range("U" & Target.Row).Interior.ColorIndex = xlColorIndexNone
ActiveSheet.Range("V" & Target.Row).FormulaR1C1 = "=AVTotal(rc[-4]:rc[-1])"
ActiveSheet.Range("W" & Target.Row).FormulaR1C1 = "=HAVS(rc[-2]:rc[-5])"
ActiveSheet.Range("X" & Target.Row).FormulaR1C1 = "=Hotel(rc[-3]:rc[-6])"
ActiveSheet.Range("Y" & Target.Row) = ""
ActiveSheet.Range("Z" & Target.Row) = ""
ActiveSheet.Range("AA" & Target.Row) = ""
Case "DE", "de", "De", "dE" ' DISCOUNT TAX EXEMPT '
ActiveSheet.Range("M" & Target.Row).Font.ColorIndex = 0
ActiveSheet.Range("Q" & Target.Row).Value = "DISC"
ActiveSheet.Range("Q" & Target.Row).Interior.ColorIndex = 44
ActiveSheet.Range("R" & Target.Row).FormulaR1C1 = "=equipDiscSUB(rc[-5],rc[-3],rc[-2])"
ActiveSheet.Range("U" & Target.Row).Value = "EXEMPT"
ActiveSheet.Range("U" & Target.Row).Interior.ColorIndex = 4
ActiveSheet.Range("V" & Target.Row).FormulaR1C1 = "=AVTotal(rc[-4]:rc[-1])"
ActiveSheet.Range("W" & Target.Row).FormulaR1C1 = "=HAVS(rc[-2]:rc[-5])"
ActiveSheet.Range("X" & Target.Row).FormulaR1C1 = "=Hotel(rc[-3]:rc[-6])"
ActiveSheet.Range("Y" & Target.Row) = ""
ActiveSheet.Range("Z" & Target.Row) = ""
ActiveSheet.Range("AA" & Target.Row).FormulaR1C1 = "=Tax(rc[-7]:rc[-9])"
Case Else
ActiveSheet.Range("M" & Target.Row).Font.ColorIndex = 0
ActiveSheet.Range("Q" & Target.Row).FormulaR1C1 = "=svcC(rc[-4]:rc[-3])"
ActiveSheet.Range("Q" & Target.Row).Interior.ColorIndex = xlColorIndexNone
ActiveSheet.Range("R" & Target.Row).FormulaR1C1 = "=equipSUB(rc[-5],rc[-3],rc[-2])"
ActiveSheet.Range("U" & Target.Row).FormulaR1C1 = "=Tax(rc[-1]:rc[-3])"
ActiveSheet.Range("U" & Target.Row).Interior.ColorIndex = xlColorIndexNone
ActiveSheet.Range("V" & Target.Row).FormulaR1C1 = "=AVTotal(rc[-4]:rc[-1])"
ActiveSheet.Range("W" & Target.Row).FormulaR1C1 = "=HAVS(rc[-2]:rc[-5])"
ActiveSheet.Range("X" & Target.Row).FormulaR1C1 = "=Hotel(rc[-3]:rc[-6])"
ActiveSheet.Range("Y" & Target.Row) = ""
ActiveSheet.Range("Z" & Target.Row) = ""
ActiveSheet.Range("AA" & Target.Row) = ""
End Select
End If
End If
Application.EnableEvents = True
End Sub