+ Reply to Thread
Results 1 to 5 of 5

VBA If/Then Code For Row/Cell Height

  1. #1
    Registered User
    Join Date
    05-03-2019
    Location
    Tampa, Florida
    MS-Off Ver
    Office 365
    Posts
    3

    VBA If/Then Code For Row/Cell Height

    Good morning all!

    I'm currently working on updating a macro I created for the purpose of formatting large sets of data into easily-readable reports. One particular part of the code is really slowing things down, but I don't know how to clean it up or make it more efficient. The purpose of problematic code is to check each cell within a defined range. If the row height of an individual must be greater than 25 in order to fit all data in a cell, the entire row is autofit to that height. If the row height is less than or equal to 25, then the row height is set to be 25. I also inserted a "Lastrow" function for excel to determine the last row with data in it and only run the above formula through that row. Unfortunately, it seems like the formula is running well beyond those parameters, so I think there may be something off with my code. Can anyone help? The code is posted below.

    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor
    Join Date
    09-19-2008
    Location
    It varies ...
    MS-Off Ver
    Office365 - 64bit
    Posts
    862

    Re: VBA If/Then Code For Row/Cell Height

    In this line:
    Please Login or Register  to view this content.
    If Lastrow = 100, you're cycling through:
    Please Login or Register  to view this content.
    Change it to:
    Please Login or Register  to view this content.
    And you don't need to cycle through each cell do you? Just each row of that range, so actually change it to:
    Please Login or Register  to view this content.
    MM
    MatrixMan.
    --------------------------------------
    If this - or any - reply helps you, remember to say thanks by clicking on *Add Reputation.
    If your issue is now resolved, remember to mark as solved - click Thread Tools at top right of thread.

  3. #3
    Forum Expert KOKOSEK's Avatar
    Join Date
    08-03-2018
    Location
    Pole in Yorkshire, UK
    MS-Off Ver
    365/2013
    Posts
    2,737

    Re: VBA If/Then Code For Row/Cell Height

    Remove 4 from J reference, like this:

    Please Login or Register  to view this content.
    Happy with my answer * Add Reputation.
    If You are happy with solution, please use Thread tools and mark thread as SOLVED.

  4. #4
    Valued Forum Contributor
    Join Date
    09-19-2008
    Location
    It varies ...
    MS-Off Ver
    Office365 - 64bit
    Posts
    862

    Re: VBA If/Then Code For Row/Cell Height

    Actually, you can do this ...
    Please Login or Register  to view this content.
    MM.

  5. #5
    Registered User
    Join Date
    05-03-2019
    Location
    Tampa, Florida
    MS-Off Ver
    Office 365
    Posts
    3

    Re: VBA If/Then Code For Row/Cell Height

    You guys are fantastic! I didn't realize that extra 4 after the J column reference was adding an extra 4000+ cells to the if, then function. It's working much faster now!

+ 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] VB Code to change Row Height
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-13-2016, 04:46 PM
  2. [SOLVED] A code to change the height of row active cell?
    By terry3218 in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 01-08-2016, 02:29 PM
  3. Autosize only height of comment box relative to height of cell comment
    By Shanthan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-05-2013, 10:25 AM
  4. Auto Row Height code
    By Scott Taylor in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 12-07-2012, 02:39 PM
  5. Need to set a row height in my code. But how?
    By copleyr in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-03-2009, 09:38 AM
  6. Row Height Code
    By icetrey in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-24-2006, 06:30 AM
  7. [SOLVED] need to dbl row height without changing height of cell next to it
    By Excel-Illiterate in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 05-15-2006, 08:15 PM

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