+ Reply to Thread
Results 1 to 3 of 3

Macro to apply a format to every cell containing only a single character

Hybrid View

  1. #1
    Registered User
    Join Date
    12-13-2013
    Location
    Bristol, England
    MS-Off Ver
    Excel 2010/2013
    Posts
    4

    Macro to apply a format to every cell containing only a single character

    Hi,

    Please excuse my spamming this board; I notice my last post is still at the top, but that issue was solved so quickly and with such aplomb that I couldn’t resist trying again with a new problem.

    I have a spreadsheet with two columns of data which will be entered by the user alphabetically. There are headings ("A", "B", etc) at intervals down the page which go over both columns and because of conflicting code I need the headings to be centred across selection rather than merged.

    What I want is a macro that finds every cell containing only a single letter, and then applies a format to that cell and the empty cell in the column immediately right of it so that the text appears centred over both columns.

    I've tried to do this with conditional formatting but it doesn't seem to be an option.

    Thanks.

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,864

    Re: Macro to apply a format to every cell containing only a single character

    insert simple macro in standard module (Alt+F11 Insert->Module):
    Sub test()
    Dim rng As Range
    For Each rng In Selection
      If Len(rng.Value) = 1 Then rng.Resize(1, 2).HorizontalAlignment = xlCenter
    Next rng
    End Sub
    Go back to your spreadsheet, select column with headings (for instance A1:A123) and run the macro (Alt+F8)

  3. #3
    Registered User
    Join Date
    12-13-2013
    Location
    Bristol, England
    MS-Off Ver
    Excel 2010/2013
    Posts
    4

    Re: Macro to apply a format to every cell containing only a single character

    Thank you. If I preset the range is there a way I could make it run at regular intervals so that the user doesn't have to update it?

+ 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. Macro to find character and delete all text in cell after the character
    By SpencerRichman in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-01-2012, 06:08 PM
  2. Does Conditional Formatting apply to each Character in a Cell?
    By e4excel in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 12-08-2009, 12:35 PM
  3. Remove a single character from a cell
    By netman in forum Excel General
    Replies: 2
    Last Post: 01-21-2008, 01:18 PM
  4. Case sensitive and single character in cell
    By praveen_khm in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-07-2006, 10:21 AM

Tags for this Thread

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