+ Reply to Thread
Results 1 to 3 of 3

Implement a Formula into a Range with VBA

  1. #1
    Registered User
    Join Date
    10-15-2012
    Location
    Oakland, CA
    MS-Off Ver
    Excel 2010
    Posts
    43

    Implement a Formula into a Range with VBA

    Hi Everyone!

    I'm very new to VBA, so please bear with me!

    I have a series of numbers starting from E2 and down, and I'm trying to apply the following formula to it using VBA:

    =IF(LEN(E2)=1,"000"&E2,IF(LEN(E2)=2,"00"&E2,IF(LEN(E2)=3,"0"&E2,IF(LEN(E2)=4,E2))))

    Basically what I want it to do is to take the current number in E2, and convert it to a #### format.

    So if E2 = 3, then I would like it to says 0003 instead.
    If E3 = 14, then I would like it to says 0014 instead.

    Can someone helps me complete this?

    I would very appreciate it!

    Thanks!

  2. #2
    Forum Expert
    Join Date
    09-20-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    2,278

    Re: Implement a Formula into a Range with VBA

    Hello
    I'm not sure if you want to apply your formula in another column adjacent to column E or if you're trying to format column E numbers with leading zeros. If the latter, then try the following code:

    Please Login or Register  to view this content.
    Here the range E2:E20 on Sheet1 is formatted.

    Hope this helps.
    DBY

  3. #3
    Registered User
    Join Date
    10-15-2012
    Location
    Oakland, CA
    MS-Off Ver
    Excel 2010
    Posts
    43

    Re: Implement a Formula into a Range with VBA

    THANK YOU!!! This is an excellent solution, and more efficient than I expect!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1