I'm new to VBA. I have a range of cells in column B with the format:
1###-2#-3##-4#
I want to enter a mid formula to get the last cell based on the fact that:
- the next cell is empty
- the cell matches the regex pattern
My code doesn't give me any errors but doesn't run.
Option Explicit
Sub DeptProgram()
Dim regex As String
Dim Pattern As String
Dim cell As Range
regex = "[0-9]{4}-[0-9]{2}-[0-9]{3}-[0-9]{2}"
For Each cell In Range("B1:B600")
If Pattern = regex And ActiveCell.Offset(1, 0) <> "" Then
ActiveCell.Offset(0, 2).Formula = "MID(B" & "activecell.Row.Offset(0,-2), 6, 11)"
End If
Next cell
End Sub
On another note: I used regex in VBA based on this article.