+ Reply to Thread
Results 1 to 6 of 6

VBA Macro for Range().End(xlUp).Row works for middle of column but oddly, not top/bottom

  1. #1
    Registered User
    Join Date
    06-24-2013
    Location
    New York
    MS-Off Ver
    Excel 2011
    Posts
    24

    VBA Macro for Range().End(xlUp).Row works for middle of column but oddly, not top/bottom

    [sample spreadsheet attached]

    My spreadsheet contains multiple rows of data, but the number of rows changes each day. Further, in Column A, there will always be exactly 4 contiguous rows of data, and I need the macro to make bold only the "cell" (Column A) of the first row in each series of data.

    Unfortunately, each series in Column A does not follow a neat predictable order, because the spacing of rows is ultimately determined by data contained in Columns B through P (although not really relevant to get this macro to work). The logic I tried to use was to identify each series of data by first finding a cell that contained a value > 0 and then searching one row above and below that cell to check which place in that particular series of data it occupied (i.e. first, second, third, or fourth position), and finally using that positioning to change the fontstyle to bold for the cell occupying the first position of the data series.

    So, if you refer to the attached spreadsheet, I would like cells: A2 ("Company A"), A8 ("Company B"), and A17 ("Company C") to turn bold. When I ran my code on the original spreadsheet with 120 rows (i.e. they can get as large as 5,000), the equivelent of only cell A8 ("Company B") turned bold while cells A2 ("Company A") and A17 ("Company C") remained unchanged.

    Any help would be much appreciated.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by justinbelkin; 07-17-2013 at 08:34 AM.

  2. #2
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: VBA Macro for Range().End(xlUp).Row works for middle of column but oddly, not top/bott

    justinbelkin,

    Welcome to the Excel Forum.

    Thanks for the workbook.

    It would appear that you have titles in row 1.

    If that is not true, and your first group starts in A1, then:


    Change this line of code:

    Please Login or Register  to view this content.

    To this:

    Please Login or Register  to view this content.


    Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

    Please Login or Register  to view this content.
    Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

    Then run the FontStyleBoldV2 macro.
    Have a great day,
    Stan

    Windows 10, Excel 2007, on a PC.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved by clicking EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  3. #3
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    935

    Re: VBA Macro for Range().End(xlUp).Row works for middle of column but oddly, not top/bott

    Your code will work better if you apply a couple of tweaks:
    Please Login or Register  to view this content.

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: VBA Macro for Range().End(xlUp).Row works for middle of column but oddly, not top/bott

    Hi justin

    Welcome to the Forum!

    If I understand your requirement try this
    Please Login or Register  to view this content.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  5. #5
    Registered User
    Join Date
    06-24-2013
    Location
    New York
    MS-Off Ver
    Excel 2011
    Posts
    24

    Re: VBA Macro for Range().End(xlUp).Row works for middle of column but oddly, not top/bott

    Thank you stanleydgromjr, rollis13, and jaslake. I am a new VBA user, and first-time forum poster. You understood my question, and all of your solutions worked perfectly. I am greatful that you all found time to respond so quickly, too. I've given you all positive "add reputation" comments. An additional thank you to stanleydgromjr and jaslake for mentioning in your email signatures how to mark an issue resolved, and how to add positive feedback to another forum member. Very helpful to know going forward.

  6. #6
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: VBA Macro for Range().End(xlUp).Row works for middle of column but oddly, not top/bott

    justinbelkin,

    You are very welcome. Glad we could help.

    Thanks for the feedback.

    And, come back anytime.

+ 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. Formula to return value for top, middle, bottom % values
    By brianjluke in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 06-13-2013, 03:05 PM
  2. Calculations for First 33%, Middle 33-67%, Bottom >67% of cells
    By DexterG in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-07-2013, 11:28 AM
  3. Replies: 1
    Last Post: 06-13-2012, 11:07 PM
  4. Move Caption In Textbox to Middle and bottom
    By Macdave_19 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-11-2008, 04:20 AM
  5. [SOLVED] Get Top X,Middle Y,Bottom Z percent Records
    By Bala in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-02-2006, 08:10 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