Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub SemiCustomChange()
- On Error GoTo CleanFail
- Application.ScreenUpdating = False
- Dim buttonName, rowNumber, sheetName, itemDescription, descriptionFormula, colorFormula, notesFormula As String
- Dim firstEmptyRow, semiCustomRow As Integer
- Dim semiCustomShape As Shape
- Dim lightGreen, darkGreen As Long
- Dim controlRange As Range
- If WorksheetExists("Semi-Custom Summary") = False Then
- MsgBox "Worksheet 'Semi-Custom Summary' not found"
- Exit Sub
- End If
- buttonName = Application.Caller
- rowNumber = Right(buttonName, Len(buttonName) - 4)
- sectionName = ActiveSheet.name
- itemDescription = ActiveSheet.Range("C" & rowNumber).value
- descriptionFormula = "='" & sectionName & "'!$C" & rowNumber '#COLUMN REFERENCE#
- colorFormula = "='" & sectionName & "'!$D" & rowNumber '#COLUMN REFERENCE#
- notesFormula = "='" & sectionName & "'!$E" & rowNumber '#COLUMN REFERENCE#
- Set semiCustomShape = ActiveSheet.Shapes(buttonName)
- Set controlRange = ActiveSheet.Range("A" & rowNumber)
- lightGreen = RGB(215, 228, 188)
- darkGreen = RGB(0, 176, 80)
- If itemDescription <> "" Then
- With Sheets("Semi-Custom Summary")
- If semiCustomShape.Fill.ForeColor.RGB = lightGreen Then
- firstEmptyRow = .Cells(.Rows.Count, "C").End(xlUp).Row + 1
- .Range("B" & firstEmptyRow).Formula = sectionName
- .Range("C" & firstEmptyRow).Formula = descriptionFormula
- .Range("D" & firstEmptyRow).Formula = colorFormula
- .Range("E" & firstEmptyRow).Formula = notesFormula
- semiCustomShape.Fill.ForeColor.RGB = darkGreen
- controlRange.value = Left(controlRange.value, 2) & "C"
- Else
- For semiCustomRow = 50 To 5 Step -1
- If .Cells(semiCustomRow, 3).value = itemDescription Then
- .Rows(semiCustomRow).Delete
- End If
- Next semiCustomRow
- semiCustomShape.Fill.ForeColor.RGB = lightGreen
- controlRange.value = Left(controlRange.value, 2) & "X"
- End If
- End With
- End If
- CleanExit:
- Application.ScreenUpdating = True
- Exit Sub
- CleanFail:
- MsgBox "Error: " & Err.Description
- Resume CleanExit
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement