This VBA script in Excel works perfectly when entered in 'ThisWorkbook', but when I enter it in a specific WorkSheet (where I want to link it to a button), it doesn't work, it gives an error on this line:
ActiveSheet.Range(Cells(intStartRow, cell.Column), Cells(lonLowRow, cell.Column)).NumberFormat = "m/d/yyyy"
The error given is: 1004
Does anybody have an idea why and how to remedy it? Thank you!!
Sub proefje()
Dim strTitleRow As String
Dim arrDates() As String
Dim arrTimes() As String
Dim intStartRow As Integer
Dim lonLowRow As Long
strTitleRow = "D5:AW5"
arrDates = Split("Last update,Last recovery test,Date installed,Key valid until", ",")
arrTimes = Split("Time", ",") 
intStartRow = 6
lonLowRow = ActiveSheet.Range("BB3").Value + ActiveSheet.Range("BE3").Value
'Date/Time job start
    ActiveSheet.Range(strTitleRow).Select
    For Each cell In Selection
        If IsInArray(cell.Value, arrDates) Then
          ActiveSheet.Range(Cells(intStartRow, cell.Column), Cells(lonLowRow, cell.Column)).NumberFormat = "m/d/yyyy"
        End If
        If IsInArray(cell.Value, arrTimes) Then
          ActiveSheet.Range(Cells(intStartRow, cell.Column), Cells(lonLowRow, cell.Column)).NumberFormat = "[$-F400]h:mm:ss AM/PM"
        End If
    Next cell
End Sub
Function IsInArray(stringToBeFound As String, arr As Variant) As Boolean
  IsInArray = (UBound(Filter(arr, stringToBeFound)) > -1)
End Function
 
     
     
    