I am making a KPI tracker for our maintenance department and have an out of service report that the end users will fill out each week. I have made a basic VBA script that works for what I want it to do, but I'm trying to think of edge cases that could break it and troubleshoot beforehand. The issue I am trying to solve is this:
The user will input their number of out of service equipment, and a formula referencing their input compared to the equipment count (raw data on another sheet) gives them a percentage. Equipment doesn't change often but when it does it's in big swathes, and since this report will be for the full year, if the equipment changes then their previous percentages will change as well. I am making this macro, assigning it to a button so when they input their equipment numbers they click this macro and it navigates to the first empty cell (the week after their inputted data), offsets to the percentages formulas and copies/pastes as values to overwrite the formula and hard code the data. I've tested and it works as intended, but as a relative VBA newb I'm not sure what could break it. Also I'm sure the code is ugly and there's a better way to format it. Would appreciate any tips or advice!
The user will input their number of out of service equipment, and a formula referencing their input compared to the equipment count (raw data on another sheet) gives them a percentage. Equipment doesn't change often but when it does it's in big swathes, and since this report will be for the full year, if the equipment changes then their previous percentages will change as well. I am making this macro, assigning it to a button so when they input their equipment numbers they click this macro and it navigates to the first empty cell (the week after their inputted data), offsets to the percentages formulas and copies/pastes as values to overwrite the formula and hard code the data. I've tested and it works as intended, but as a relative VBA newb I'm not sure what could break it. Also I'm sure the code is ugly and there's a better way to format it. Would appreciate any tips or advice!
VBA Code:
Option Explicit
Sub FindFirstEmptyCell()
Dim c
Dim d
Application.ScreenUpdating = False
Application.AlertBeforeOverwriting = False
'Find first empty cell then select percentages below
For Each c In Range("C4:X7").Cells
If c = "" Then
c.Select
ActiveCell.Offset(5, -1).Select
Exit For
End If
Next
'Copy data in formulas and paste as values to overwrite
Range(ActiveCell, ActiveCell.Offset(3, 0)).Copy
Range(ActiveCell, ActiveCell).PasteSpecial xlPasteValues
For Each d In Range("C15:X18").Cells
If d = "" Then
d.Select
ActiveCell.Offset(5, -1).Select
Exit For
End If
Next
Range(ActiveCell, ActiveCell.Offset(3, 0)).Copy
Range(ActiveCell, ActiveCell).PasteSpecial xlPasteValues
Range("A1").Select
Range("A1").ClearContents
Application.ScreenUpdating = True
Application.AlertBeforeOverwriting = True
End Sub