Option Explicit
Function DerColOccup(xrg As Range, Optional relatif)
Dim N, C
If IsMissing(relatif) Then C = DerColOccupLettre(xrg) Else C = DerColOccupLettre(xrg, 1)
If IsMissing(relatif) Then N = DerColOccupNombre(xrg) Else N = DerColOccupNombre(xrg, 1)
If IsNumeric(C) And IsNumeric(N) Then
DerColOccup = IIf(C > N, C, N)
ElseIf IsError(C) Then
DerColOccup = C
Else
DerColOccup = N
End If
End Function
Function DerColOccupLettre(xrg As Range, Optional relatif)
Dim colinf, F As Worksheet, base&
Set F = xrg.Parent
If xrg Is Nothing Then DerColOccupLettre = CVErr(xlErrRef): Exit Function
If xrg.Rows.Count > 1 Then DerColOccupLettre = CVErr(xlErrRef): Exit Function
On Error Resume Next
colinf = Application.Match(String(255, "z"), xrg)
Do
If IsError(colinf) Then
colinf = 0
Exit Do
Else
If xrg(colinf) = "" Then
If colinf = 1 Then
colinf = 0
Exit Do
Else
colinf = Application.Match(String(255, "z"), xrg.Resize(, colinf - 1))
End If
Else
Exit Do
End If
End If
Loop
If colinf <> 0 Then DerColOccupLettre = colinf + IIf(IsMissing(relatif), xrg.Column - 1, 0) Else DerColOccupLettre = 0
End Function
Function DerColOccupNombre(xrg As Range, Optional relatif)
Dim colinf, F As Worksheet, base&
Set F = xrg.Parent
If xrg Is Nothing Then DerColOccupNombre = CVErr(xlErrRef): Exit Function
If xrg.Rows.Count > 1 Then DerColOccupNombre = CVErr(xlErrRef): Exit Function
On Error Resume Next
colinf = Application.Match(1E+99, xrg)
If IsError(colinf) Then colinf = 0
If colinf <> 0 Then DerColOccupNombre = colinf + IIf(IsMissing(relatif), xrg.Column - 1, 0) Else DerColOccupNombre = 0
End Function