How to convert any types format into Text with 5 digits in selection?
For instance, the content I select is "234", and I want it to convert to "00234". Just like the function "TEXT" in excel. How can I realize it promptly in VBA?
Thanks!!!
How to convert any types format into Text with 5 digits in selection?
For instance, the content I select is "234", and I want it to convert to "00234". Just like the function "TEXT" in excel. How can I realize it promptly in VBA?
Thanks!!!
VBA's Format function works the same as TEXT.
_
...How to Cross-post politely...
..Wrap code by selecting the code and clicking the # or read this. Thank you.
but I tryit doesn't work.Please Login or Register to view this content.
Perhaps
Please Login or Register to view this content.
Last edited by jindon; 08-19-2014 at 08:52 PM.
http://i.hizliresim.com/X2pkBD.jpg
TextBox2 = Format(TextBox1, "00000")
deleted......
Perhaps
Range("A1").Select
Selection.NumberFormat = "00000"
@jindon what has happened??
Thank you guys!
@jindon your code is what I exactly want! But how does it work? Why use "@" and why put a $ after Fomat??
However, another problem shows up, it doesn't work when I choose a range.
Please Login or Register to view this content.
Last edited by qzqzjcjp; 08-19-2014 at 09:23 PM.
Hello
selection.JPG
Select worksheet-> selection change event and write the code, there
Regards,With Selection
.NumberFormat = "@"
.Value = Format$(Selection, "00000")
End With
It still doesn't work. The error is always: Run-time error '13' Type mismatch. I modified the code a little bit and it works!!!
But another problem comes up, If I select the whole column or whole cells, it costs too much time to run.Please Login or Register to view this content.
Last edited by qzqzjcjp; 08-19-2014 at 10:46 PM.
Change
toPlease Login or Register to view this content.
Please Login or Register to view this content.
Thanks!!! Everyone!!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks