Advertisement
Guest User

VehicleWorkbook_SemiCustomChange

a guest
Mar 20th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. Sub SemiCustomChange()
  2.  
  3. On Error GoTo CleanFail
  4.  
  5. Application.ScreenUpdating = False
  6.  
  7. Dim buttonName, rowNumber, sheetName, itemDescription, descriptionFormula, colorFormula, notesFormula As String
  8. Dim firstEmptyRow, semiCustomRow As Integer
  9. Dim semiCustomShape As Shape
  10. Dim lightGreen, darkGreen As Long
  11. Dim controlRange As Range
  12.  
  13. If WorksheetExists("Semi-Custom Summary") = False Then
  14. MsgBox "Worksheet 'Semi-Custom Summary' not found"
  15. Exit Sub
  16. End If
  17.  
  18. buttonName = Application.Caller
  19. rowNumber = Right(buttonName, Len(buttonName) - 4)
  20. sectionName = ActiveSheet.name
  21. itemDescription = ActiveSheet.Range("C" & rowNumber).value
  22. descriptionFormula = "='" & sectionName & "'!$C" & rowNumber '#COLUMN REFERENCE#
  23. colorFormula = "='" & sectionName & "'!$D" & rowNumber '#COLUMN REFERENCE#
  24. notesFormula = "='" & sectionName & "'!$E" & rowNumber '#COLUMN REFERENCE#
  25. Set semiCustomShape = ActiveSheet.Shapes(buttonName)
  26. Set controlRange = ActiveSheet.Range("A" & rowNumber)
  27. lightGreen = RGB(215, 228, 188)
  28. darkGreen = RGB(0, 176, 80)
  29.  
  30. If itemDescription <> "" Then
  31. With Sheets("Semi-Custom Summary")
  32. If semiCustomShape.Fill.ForeColor.RGB = lightGreen Then
  33. firstEmptyRow = .Cells(.Rows.Count, "C").End(xlUp).Row + 1
  34. .Range("B" & firstEmptyRow).Formula = sectionName
  35. .Range("C" & firstEmptyRow).Formula = descriptionFormula
  36. .Range("D" & firstEmptyRow).Formula = colorFormula
  37. .Range("E" & firstEmptyRow).Formula = notesFormula
  38. semiCustomShape.Fill.ForeColor.RGB = darkGreen
  39. controlRange.value = Left(controlRange.value, 2) & "C"
  40. Else
  41. For semiCustomRow = 50 To 5 Step -1
  42. If .Cells(semiCustomRow, 3).value = itemDescription Then
  43. .Rows(semiCustomRow).Delete
  44. End If
  45. Next semiCustomRow
  46. semiCustomShape.Fill.ForeColor.RGB = lightGreen
  47. controlRange.value = Left(controlRange.value, 2) & "X"
  48. End If
  49. End With
  50. End If
  51.  
  52. CleanExit:
  53. Application.ScreenUpdating = True
  54. Exit Sub
  55. CleanFail:
  56. MsgBox "Error: " & Err.Description
  57. Resume CleanExit
  58.  
  59. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement