Converting Numbers to Text to Keep Leading 0's - Dynamic Range

ac1212

New Member
Joined
Jul 13, 2021
Messages
5
Office Version
  1. 2019
Platform
  1. Windows
Hi,

I am trying to covert numbers in in a column to text in order to keep the leading zero's. I have managed to get the below to work but want to be able to have the range as dynamic not set on the end being row 100.

I need to have all cells with numbers in column A to be 5 characters long with leading zero's if needed.

Thanks for the help!

VBA Code:
  Dim cell As Range
   
    Range("A2:A100").NumberFormat = "@"
   
    For Each cell In Range("A2:A100")
        cell = Format(cell, "00000")
    Next cell
 
Glad to help & thanks for the feedback.
 
  • Like
Reactions: skn
Upvote 0

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
I have the similar scenario except I want to display a value as (87612E106) instead of 8.7612E+110. Any idea how to deal with this? Please excuse my ignorance. Thanks inadvance.
 
Upvote 0
As this is a different question to the op, please start a thread of your own. Thanks
 
  • Like
Reactions: skn
Upvote 0

Forum statistics

Threads
1,214,551
Messages
6,120,156
Members
448,948
Latest member
spamiki

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top