I am looking for a way to create a toggle, which I could use to change cell value to "General" format or "Text" format as well as making it appear as text, rather than a number.
Let's say I have 3 values: 2839283 8572839 5922038
What I have tried (it works) is this:
Dim MyRng as Range
Dim MyCell as Range
Set MyRng = Selection
if MyRng.NumberFormat = "General" Then
For each MyCell in MyRng
MyCell.NumberFormat = "@"
MyCell.Value2 = CStr(MyCell.Value2)
next MyCell
Else
For each MyCell in MyRng
MyCell.NumberFormat = "General"
MyCell.Value2 = MyCell.Value2
next MyCell
End if
Is there any way to achieve the same objective without using a for loop? I am trying to make it efficient and when this macro is applied to 20k rows then... Well, it works but rather slow.
I have tried to simply call:
MyRng.NumberFormat
MyRng.Value2
And it works with conversion from text to numbers, but sadly it shows mismatch error when trying to convert numbers to text (that is why I have used a loop there).
Any ideas?