+ Reply to Thread
Results 1 to 2 of 2

Help with Center Across Selection Getting Reset Running at END IF Portion of VBA Code

  1. #1
    Registered User
    Join Date
    06-13-2013
    Location
    USA
    MS-Off Ver
    Excel 365
    Posts
    32

    Help with Center Across Selection Getting Reset Running at END IF Portion of VBA Code

    Having trouble with Code #1 below, I'm trying to just create a simple macro for my use case as described below. I am running into an issue where xlCenterAcrossSelection command is getting reset after it gets applied. I've run through the F8 Step Into Debug and it looks like CenterAcrossSelection ALWAYS breaks at the END IF argument highlighted blue/bold below in my code (i.e. it will apply correctly in the code then when it reaches ENDIF, the horizontalalignment gets reset to xlCenter). Any idea how to fix this? I strangely enough have another keyboard shortcut assigned to Code #2 that works perfectly for just this issue.

    Use case: when I make a selection (say 3 cells - A1:C1 where A1 has "the" in it and B1 / C1 are empty), then running this macro toggles between State 1 [CenterAcrossSelection, bolded, and underlined accounting style] and State 2 [all cells are back to center aligned in A1:C1, not centered across selection, no underline accounting style].

    Code #1 that isn't working as it should be for a style switch across selection
    Please Login or Register  to view this content.

    Code #2 that works perfectly for just alternating between CenterAcrossSelection and not
    Please Login or Register  to view this content.

  2. #2
    Registered User
    Join Date
    06-13-2013
    Location
    USA
    MS-Off Ver
    Excel 365
    Posts
    32

    Re: Help with Center Across Selection Getting Reset Running at END IF Portion of VBA Code

    second thought, would this code be better applied in a "Select Case" argument? I tried below and it seems to be working...but not sure this is best practices / most efficient code.

    Please Login or Register  to view this content.
    Last edited by ExcelMeister10520; 09-10-2019 at 11:27 PM.

+ 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. VBA code to expand selection based on value in next cell and then merge-and-center
    By amarkham in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-07-2018, 06:15 PM
  2. Center down selection
    By Cheeky Charlie in forum Excel General
    Replies: 0
    Last Post: 02-12-2009, 11:38 AM
  3. [SOLVED] center across selection formatting
    By Dave Breitenbach in forum Excel General
    Replies: 1
    Last Post: 11-14-2005, 10:00 PM
  4. center across the selection
    By Suraj Aryal in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 10-09-2005, 11:05 AM
  5. [SOLVED] Running code on a drop down selection change
    By Steve Haack in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-26-2005, 12:06 AM
  6. Replies: 1
    Last Post: 03-29-2005, 08:06 AM
  7. How do I UN Center a Selection
    By KevinK in forum Excel General
    Replies: 3
    Last Post: 02-08-2005, 10:06 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