+ Reply to Thread
Results 1 to 8 of 8

left padding (with given character)

  1. #1
    Registered User
    Join Date
    10-25-2016
    Location
    Brussels
    MS-Off Ver
    2010
    Posts
    17

    left padding (with given character)

    Hi Folks

    For each cell in a selection I would want the following executed:
    set the cell format to 'text'
    select the needed length of the cell by InputBox [=Var1]
    select the character to use for padding by inputbox [=Var2]
    left pad the cells according to the above input.

    Any help very much appreciated.

    Grtz
    A

  2. #2
    Forum Expert Roel Jongman's Avatar
    Join Date
    03-28-2015
    Location
    Netherlands
    MS-Off Ver
    Office 365
    Posts
    1,483

    Re: left padding (with given character)

    Have a look if the code below gives you what you need

    Please Login or Register  to view this content.

    Just to point out in case you dont know...
    You also have several options without VBA please read this link to see how you can fill out a cell with a function or with (custom) cell formatting
    https://www.extendoffice.com/documen...r-in-cell.html

  3. #3
    Registered User
    Join Date
    10-25-2016
    Location
    Brussels
    MS-Off Ver
    2010
    Posts
    17

    Re: left padding (with given character)

    Hi Roel

    Thanks for your answer and code.
    My question was not so clear, sorry.

    Var1 = is the desired length of the string in the cells, not the number of repeats

    eg.
    Var1 = 9
    Var2 = a

    Then eg.
    12526 ==> aaa12526
    526 ==> aaaaaaa526
    12526000 ==> a12526000
    125265626 ==> 125265626

    Thx for your effort/feedback.
    i kind of like macroes, since they do the job quite quickly...

    Grtz
    A

  4. #4
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: left padding (with given character)

    Try
    Please Login or Register  to view this content.
    Last edited by nigelog; 03-04-2019 at 07:54 AM.

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: left padding (with given character)

    Try
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    10-25-2016
    Location
    Brussels
    MS-Off Ver
    2010
    Posts
    17

    Re: left padding (with given character)

    Hi Nigelog
    Thx for your feedback.
    That does the trick when one cell is selected; when a range selected marco halts at
    Content = Selection.Text

  7. #7
    Forum Expert Roel Jongman's Avatar
    Join Date
    03-28-2015
    Location
    Netherlands
    MS-Off Ver
    Office 365
    Posts
    1,483

    Re: left padding (with given character)

    Ok, lets try with this code then..
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    10-25-2016
    Location
    Brussels
    MS-Off Ver
    2010
    Posts
    17

    Re: left padding (with given character)

    Hi Roel

    That does the trick!
    Thx very much, you made my day.

    Thx for the other suggestions; quite learned from it as well

    Grtz
    A

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] How to use LEFT and RIGHT to delete last character
    By nicolaivinther in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-06-2014, 09:53 AM
  2. Box as rows and padding left
    By toplisek in forum Excel General
    Replies: 1
    Last Post: 07-28-2014, 04:46 AM
  3. Replies: 3
    Last Post: 11-20-2012, 10:03 PM
  4. Replies: 3
    Last Post: 10-31-2012, 11:20 PM
  5. Replies: 2
    Last Post: 08-19-2008, 07:18 AM
  6. left padding + blank
    By Alex in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-05-2006, 06:25 PM
  7. left padding + blank
    By Alex in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 01-05-2006, 06:25 PM

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