I want to embed a procedure in an Excel worksheet that will determine when the cell format changes, for example. from text to number.
But I can not figure out how to get the cell format type. I tried using the Worksheet_Change event handler to check the data type as follows:
Private Sub worksheet_change(ByVal Target As Range) If Target.Address = "a1" Then If VarType(Target) <> 5 Then MsgBox "cell format has been changed" End If End If End Sub
But with this code in place, if I change the data type of cell A1 from Number to Text, Worksheet_Change does not start; an event handler is only called if I modify the contents of the cell.
In addition, this procedure can determine if the content changes from a number to an alphabetical string, for example. from "35.12" to "abcd", but not a number number to a text number; if I set cell B1 to text, then enter β40β, then paste the contents of cell B1 into cell A1, vartype() still returns β5β, so the warning does not fire.
How can I determine if the format has changed, regardless of whether the type of content has changed?
vba excel-vba excel
sigil
source share