I need to make a Workbook_BeforeSave in my Personal.XLSB file
However, I cannot get the code to work.
Code
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim wkb As Workbook
Set wkb = Workbooks(ActiveWorkbook.Name)
Dim wks As Worksheet
For Each wks In wkb.Worksheets
If wks.Name = "Datasheet" Or wks.Name = "ApplicationDriver" Then
Dim rowColumn, rowIterator
rowColumn = 1
rowIterator = 2
'Find the row column
Do Until wks.Cells(1, rowColumn).Value = ""
If LCase(wks.Cells(1, rowColumn).Value) = "row" Then
Exit Do
End If
rowColumn = rowColumn + 1
Loop
'Add the row values as long as the scenario is populated
Do Until rowIterator = wks.UsedRange.Rows.Count + 1
wks.Cells(rowIterator, rowColumn).NumberFormat = "@"
wks.Cells(rowIterator, rowColumn).Value = (rowIterator - 1)
rowIterator = rowIterator + 1
Loop
End If
Next
End Sub
Can anyone help?